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 |
import dateutil |
import dateutil |
from dateutil.parser import * |
from dateutil.parser import * |
from datetime import * |
from datetime import * |
|
|
#http://www.doughellmann.com/PyMOTW/abc/ |
#http://www.doughellmann.com/PyMOTW/abc/ |
class ScraperImplementation(genericScrapers.GenericOAICDisclogScraper): |
class ScraperImplementation(genericScrapers.GenericOAICDisclogScraper): |
def getTable(self,soup): |
def getTable(self,soup): |
return soup.find(class_ = "inner-column").table |
return soup.find(class_ = "inner-column").table |
def getRows(self,table): |
def getRows(self,table): |
return table.tbody.find_all('tr',recursive=False) |
return table.tbody.find_all('tr',recursive=False) |
def getColumnCount(self): |
def getColumnCount(self): |
return 3 |
return 3 |
def getColumns(self,columns): |
def getColumns(self,columns): |
(date, title, description) = columns |
(date, title, description) = columns |
return (date, date, title, description, None) |
return (date, date, title, description, None) |
def getDate(self, content, entry, doc): |
def getDate(self, content, entry, doc): |
i = 0 |
i = 0 |
date = "" |
date = "" |
for string in content.stripped_strings: |
for string in content.stripped_strings: |
if i ==1: |
if i ==1: |
date = string |
date = string |
i = i+1 |
i = i+1 |
edate = parse(date, dayfirst=True, fuzzy=True).strftime("%Y-%m-%d") |
edate = parse(date, dayfirst=True, fuzzy=True).strftime("%Y-%m-%d") |
print edate |
print edate |
doc.update({'date': edate}) |
doc.update({'date': edate}) |
return |
return |
def getTitle(self, content, entry, doc): |
def getTitle(self, content, entry, doc): |
i = 0 |
i = 0 |
title = "" |
title = "" |
for string in content.stripped_strings: |
for string in content.stripped_strings: |
if i < 2: |
if i < 2: |
title = title + string |
title = title + string |
i = i+1 |
i = i+1 |
doc.update({'title': title}) |
doc.update({'title': title}) |
#print title |
#print title |
return |
return |
|
|
if __name__ == '__main__': |
if __name__ == '__main__': |
|
#http://www.csiro.au/Portals/About-CSIRO/How-we-work/Governance/FOI-Request-Disclosure-Log-2012-13.aspx |
|
#http://www.csiro.au/Portals/About-CSIRO/How-we-work/Governance/FOI-Request-Disclosure-Log-2011-12.aspx |
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() |
|
|