|
|
1 |
import sys,os |
|
|
2 |
sys.path.insert(0, os.path.join(os.path.dirname(__file__) or '.', '../')) |
|
|
3 |
import genericScrapers |
|
|
4 |
import scrape |
|
|
5 |
from bs4 import BeautifulSoup |
|
|
6 |
|
|
|
7 |
#http://www.doughellmann.com/PyMOTW/abc/ |
|
|
8 |
class ScraperImplementation(genericScrapers.GenericOAICDisclogScraper): |
|
|
9 |
def getDescription(self,content, entry,doc): |
|
|
10 |
link = None |
|
|
11 |
links = [] |
|
|
12 |
description = "" |
|
|
13 |
for atag in entry.find_all('a'): |
|
|
14 |
if atag.has_key('href'): |
|
|
15 |
link = scrape.fullurl(self.getURL(),atag['href']) |
|
|
16 |
(url,mime_type,htcontent) = scrape.fetchURL(scrape.docsdb, link, "foidocuments", self.getAgencyID(), False) |
|
|
17 |
if htcontent != None: |
|
|
18 |
if mime_type == "text/html" or mime_type == "application/xhtml+xml" or mime_type =="application/xml": |
|
|
19 |
# http://www.crummy.com/software/BeautifulSoup/documentation.html |
|
|
20 |
soup = BeautifulSoup(htcontent) |
|
|
21 |
for row in soup.find(class_ = "ms-rteTable-GreyAlternating").find_all('tr'): |
|
|
22 |
if row != None: |
|
|
23 |
rowtitle = row.find('th').string |
|
|
24 |
description = description + "\n" + rowtitle + ": " |
|
|
25 |
for text in row.find('td').stripped_strings: |
|
|
26 |
description = description + text |
|
|
27 |
for atag in row.find_all("a"): |
|
|
28 |
if atag.has_key('href'): |
|
|
29 |
links.append(scrape.fullurl(link,atag['href'])) |
|
|
30 |
|
|
|
31 |
if links != []: |
|
|
32 |
doc.update({'links': links}) |
|
|
33 |
if description != "": |
|
|
34 |
doc.update({ 'description': description}) |
|
|
35 |
|
|
|
36 |
def getColumnCount(self): |
|
|
37 |
return 2 |
|
|
38 |
def getTable(self,soup): |
|
|
39 |
return soup.find(class_ = "ms-rteTable-GreyAlternating") |
|
|
40 |
def getColumns(self,columns): |
|
|
41 |
(date, title) = columns |
|
|
42 |
return (title, date, title, title, None) |
|
|
43 |
|
|
|
44 |
if __name__ == '__main__': |
|
|
45 |
print 'Subclass:', issubclass(ScraperImplementation, genericScrapers.GenericOAICDisclogScraper) |
|
|
46 |
print 'Instance:', isinstance(ScraperImplementation(), genericScrapers.GenericOAICDisclogScraper) |
|
|
47 |
ScraperImplementation().doScrape() |
|
|
48 |
# old site too http://archive.treasury.gov.au/content/foi_publications.asp |
|
|
49 |
|