Permalink
Browse files

Update scraper.py

  • Loading branch information...
JureStabuc committed Oct 10, 2015
1 parent 5e6100f commit 88d6e657d7ac294322eac02d02e060c170cc5299
Showing with 22 additions and 0 deletions.
  1. +22 −0 scraper.py
View
@@ -22,3 +22,25 @@
# 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( 'apple', 2 )
for i,e in enumerate(items):
print '%d: %s' % (i+1,e,)

0 comments on commit 88d6e65

Please sign in to comment.