Crawl a website with scrapy and store extracted results with MongoDB
11–20 of 20 posts
Re: Crawl a website with scrapy and store extracted results with MongoDB
#12 import httplib2, lxml, pyquery
h = httplib2.Http(".cache")
def get(url):
resp, content = h.request( url, headers={'cache-control':'max-age=3600'})
return pyquery.PyQuery( lxml.etree.HTML(content) )
This gives you a little function that fetches any URL as a jquery-like object: pq = get("http://foo.com/bar")
checkboxes = pq('form input[type=checkbox]')
nextpage = pq('a.next').attr('href')
And of course all of the requests are cached using whatever cache headers you want, so repeated requests will load instantly as you iterate.Just something else to throw in the toolbelt ...
Re: Crawl a website with scrapy and store extracted results with MongoDB
#13Also check this out for a pretty good discussion on scraping http://pyvideo.org/video/609/web-scraping-reliably-and-effic...
Yeah, I actually learnt scraping from Asheesh :) He's awesome.
Keep meaning to check out more of the Pycon vids
Re: Crawl a website with scrapy and store extracted results with MongoDB
#14Cool. BTW, is there a reason for naming the file "isullshit_spiders.py" and not as "is b ullshit_spiders.py"? :)
Re: Crawl a website with scrapy and store extracted results with MongoDB
#15For really quick one-off scraping, httplib2+lxml+PyQuery is a pretty neat combination: import httplib2, lxml, pyquery h = httplib2.Http(".cache") def get(url): resp, content = h.request( url, headers={'cache-control':'max-age=3600'}) return pyquery.PyQuery( lxml.etree.HTML(content) ) This gives you a little function that fetches any URL as a jquery-like object: pq = get("http://foo.com/bar") checkboxes = pq('form inp…
Re: Crawl a website with scrapy and store extracted results with MongoDB
#16For really quick one-off scraping, httplib2+lxml+PyQuery is a pretty neat combination: import httplib2, lxml, pyquery h = httplib2.Http(".cache") def get(url): resp, content = h.request( url, headers={'cache-control':'max-age=3600'}) return pyquery.PyQuery( lxml.etree.HTML(content) ) This gives you a little function that fetches any URL as a jquery-like object: pq = get("http://foo.com/bar") checkboxes = pq('form inp…
Have checked out kenneth reitz's requests? Its fantastic, you might like it
Re: Crawl a website with scrapy and store extracted results with MongoDB
#17Earlier quoted context omitted.
Have checked out kenneth reitz's requests? Its fantastic, you might like it
Link, for the interested: https://github.com/kennethreitz/requests
import requests
from lxml import etree
jquery_like_page = etree.HTML(requests.get('url').text)Re: Crawl a website with scrapy and store extracted results with MongoDB
#18I really want to read. Topic is right down my alley. Unfortunately, the page is literally broken and unreadable on Android ICS with Chrome :(