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 dateutil |
import dateutil |
from dateutil.parser import * |
from dateutil.parser import * |
from datetime import * |
from datetime import * |
import scrape |
import scrape |
from bs4 import BeautifulSoup |
from bs4 import BeautifulSoup |
class ScraperImplementation(genericScrapers.GenericOAICDisclogScraper): |
class ScraperImplementation(genericScrapers.GenericOAICDisclogScraper): |
|
|
def __init__(self): |
def __init__(self): |
super(ScraperImplementation, self).__init__() |
super(ScraperImplementation, self).__init__() |
def getTable(self, soup): |
def getTable(self, soup): |
return soup.find(id='content') |
return soup.find(id='zone-content') |
|
|
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_attr('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": |
soup = BeautifulSoup(htcontent) |
soup = BeautifulSoup(htcontent) |
row = soup.find(id="foidetails") |
row = soup.find(id="foidetails") |
if row == None: |
if row == None: |
row = soup.find(id="content").table |
row = soup.find(id="content").table |
if row == None: |
if row == None: |
row = soup.find(id="content") |
row = soup.find(id="content") |
description = ''.join(row.stripped_strings) |
description = ''.join(row.stripped_strings) |
for atag in row.find_all("a"): |
for atag in row.find_all("a"): |
if atag.has_attr('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 3 |
return 3 |
|
|
def getColumns(self, columns): |
def getColumns(self, columns): |
(id, title, date) = columns |
(id, title, date) = columns |
return (id, date, title, title, None) |
return (id, 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() |
|
|