import sys,os |
import sys,os |
sys.path.insert(0, os.path.join(os.path.dirname(__file__) or '.', '../')) |
sys.path.insert(0, os.path.join(os.path.dirname(__file__) or '.', '../')) |
import genericScrapers |
import genericScrapers |
import scrape |
import scrape |
from bs4 import BeautifulSoup |
from bs4 import BeautifulSoup |
|
|
#http://www.doughellmann.com/PyMOTW/abc/ |
#http://www.doughellmann.com/PyMOTW/abc/ |
class ScraperImplementation(genericScrapers.GenericOAICDisclogScraper): |
class ScraperImplementation(genericScrapers.GenericOAICDisclogScraper): |
def getDescription(self,content, entry,doc): |
def getDescription(self,content, entry,doc): |
link = None |
link = None |
links = [] |
links = [] |
description = "" |
description = "" |
for atag in entry.find_all('a'): |
for atag in entry.find_all('a'): |
if atag.has_key('href'): |
if atag.has_attr('href'): |
link = scrape.fullurl(self.getURL(),atag['href']) |
link = scrape.fullurl(self.getURL(),atag['href']) |
(url,mime_type,htcontent) = scrape.fetchURL(scrape.docsdb, link, "foidocuments", self.getAgencyID(), False) |
(url,mime_type,htcontent) = scrape.fetchURL(scrape.docsdb, link, "foidocuments", self.getAgencyID(), False) |
if htcontent != None: |
if htcontent != None: |
if mime_type == "text/html" or mime_type == "application/xhtml+xml" or mime_type =="application/xml": |
if mime_type == "text/html" or mime_type == "application/xhtml+xml" or mime_type =="application/xml": |
# http://www.crummy.com/software/BeautifulSoup/documentation.html |
# http://www.crummy.com/software/BeautifulSoup/documentation.html |
soup = BeautifulSoup(htcontent) |
soup = BeautifulSoup(htcontent) |
rowtitle = soup.find(class_ = "wc-title").find("h1").string |
rowtitle = soup.find(class_ = "wc-title").find("h1").string |
if rowtitle != None: |
if rowtitle != None: |
description = rowtitle + ": " |
description = rowtitle + ": " |
for row in soup.find(class_ ="wc-content").find_all('td'): |
for row in soup.find(class_ ="wc-content").find_all('td'): |
if row != None: |
if row != None: |
for text in row.stripped_strings: |
for text in row.stripped_strings: |
description = description + text + "\n" |
description = description + text + "\n" |
for atag in row.find_all("a"): |
for atag in row.find_all("a"): |
if atag.has_key('href'): |
if atag.has_attr('href'): |
links.append(scrape.fullurl(link,atag['href'])) |
links.append(scrape.fullurl(link,atag['href'])) |
|
|
if links != []: |
if links != []: |
doc.update({'links': links}) |
doc.update({'links': links}) |
if description != "": |
if description != "": |
doc.update({ 'description': description}) |
doc.update({ 'description': description}) |
|
|
def getColumnCount(self): |
def getColumnCount(self): |
return 2 |
return 2 |
def getTable(self,soup): |
def getTable(self,soup): |
return soup.find(class_ = "ms-rteTable-default") |
return soup.find(class_ = "ms-rteTable-default") |
def getColumns(self,columns): |
def getColumns(self,columns): |
(date, title) = columns |
(date, title) = columns |
return (title, date, title, title, None) |
return (title, date, title, title, None) |
|
|
if __name__ == '__main__': |
if __name__ == '__main__': |
print 'Subclass:', issubclass(ScraperImplementation, genericScrapers.GenericOAICDisclogScraper) |
print 'Subclass:', issubclass(ScraperImplementation, genericScrapers.GenericOAICDisclogScraper) |
print 'Instance:', isinstance(ScraperImplementation(), genericScrapers.GenericOAICDisclogScraper) |
print 'Instance:', isinstance(ScraperImplementation(), genericScrapers.GenericOAICDisclogScraper) |
ScraperImplementation().doScrape() |
ScraperImplementation().doScrape() |
|
|