Skip to content

Commit

Permalink
Update scraper.py
Browse files Browse the repository at this point in the history
  • Loading branch information
Carmen-Aguilar committed Feb 25, 2018
1 parent cde0aa6 commit 8e2c840
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions scraper.py
Expand Up @@ -22,3 +22,26 @@
# All that matters is that your final data is written to an SQLite database
# called "data.sqlite" in the current working directory which has at least a table
# called "data".

import urllib2
from xml.dom.minidom import parseString

def get_google_new_results( term, count ):
results = []
obj = parseString( urllib2.urlopen('http://news.google.com/news?q=%s&output=rss' % term).read() )

elements = obj.getElementsByTagName('title')[2:] # To get rid of unwanted title elements in XML doc
links = obj.getElementsByTagName('link')[2:]
print links
for element in elements[:count]:
headline = element.childNodes[0].data
for link in links:
url = link.childNodes[0].data.split('=')[-1]
newssearch = headline + ' -> ' + url
results.append( newssearch )

return results

items = get_google_new_results('olive+oil+fraud', 50 )
for i,e in enumerate(items):
print '%d: %s' % (i+1,e,)

0 comments on commit 8e2c840

Please sign in to comment.