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 |
#RSS feed not detailed |
import scrape |
|
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 = [] |
|
description = "" |
for atag in entry.find_all('a'): |
for atag in entry.find_all('a'): |
if atag.has_key('href'): |
if atag.has_key('href'): |
link = scrape.fullurl(url,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(content) |
soup = BeautifulSoup(htcontent) |
links = [] |
for row in soup.find(class_ = "ms-rteTable-GreyAlternating").find_all('tr'): |
description = "" |
if row != None: |
dldivs = soup.find('div',class_="download") |
rowtitle = row.find('th').string |
if dldivs != None: |
description = description + "\n" + rowtitle + ": " |
for atag in dldivs.find_all("a"): |
for text in row.find('td').stripped_strings: |
if atag.has_key('href'): |
description = description + text |
links.append(scrape.fullurl(url,atag['href'])) |
for atag in row.find_all("a"): |
nodldivs = soup.find('div',class_="incompleteNotification") |
if atag.has_key('href'): |
if nodldivs != None and nodldivs.stripped_strings != None: |
links.append(scrape.fullurl(link,atag['href'])) |
for text in nodldivs.stripped_strings: |
|
description = description + text |
if links != []: |
for row in soup.table.find_all('tr'): |
doc.update({'links': links}) |
if row != None: |
if description != "": |
description = description + "\n" + row.find('th').string + ": " |
doc.update({ 'description': description}) |
for text in row.find('div').stripped_strings: |
|
description = description + text |
|
if links != []: |
|
doc.update({'links': links}) |
|
if description != "": |
|
doc.update({ 'description': description}) |
|
def getColumnCount(self): |
def getColumnCount(self): |
return 2 |
return 2 |
|
def getTable(self,soup): |
|
return soup.find(class_ = "ms-rteTable-GreyAlternating") |
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() |
|
|