json - python scrape webpage and parse the content -
i want scrape data on link
http://www.realclearpolitics.com/epolls/json/5491_historical.js?1453388629140&callback=return_json
i not sure type of link is, html or json or else. sorry bad web knowledge. try use following code scrape:
import requests url='http://www.realclearpolitics.com/epolls/json/5491_historical.js?1453388629140&callback=return_json' source=requests.get(url).text
the type of source unicode. try use urllib2 scrape like:
source2=urllib2.urlopen(url).read()
the type of source2 string. not sure method better. because link not normal webpage contains different tags. if want clean scraped data , form dataframe data (like pandas dataframe), method or process should follow/
thanks.
the returned response text containing valid json data within it. can validate on own using service http://jsonlint.com/ if want. doing copy code within brackets
return_json("json code copy")
in order make use of data need parse in program. here example: https://docs.python.org/2/library/json.html
Comments
Post a Comment