BeautifulSoup, has received a lot of positive press on HN over the years so when I needed to do some heavy scraping I gave it a spin. It was a total disappointment. It's fine if you are scraping a small set of similar pages from a single site but if you are scraping a large number of pages across many sites and esp pages with text encoding other than ascii / utf-8 it choaks so frequently as to be useless. BeautifulSo…
Web Scraping 101 with Python
71–80 of 80 posts
Re: Web Scraping 101 with Python
#72PyQuery is pretty awesome ( https://pypi.python.org/pypi/pyquery ) Using Requests to download the document, pump it into PyQuery and you can use any jQuery style selectors to get text, attributes and all sorts of other stuff. Example; Here's how to scrape the hacker news homepage https://gist.github.com/samarudge/035ab8aaca224415cb49 (that code could probably be improved but I only spent a couple of minutes on it)
Re: Web Scraping 101 with Python
#73Re: Web Scraping 101 with Python
#74What would you recommend for automating website interaction (use a bot to get betting numbers and then log in and automate a bet without any human interaction) some sites use an API (betfair) but some don't.
Re: Web Scraping 101 with Python
#75Isnt Nutch state of the art right now?
Re: Web Scraping 101 with Python
#76Earlier quoted context omitted.
I'll second, lxml.html is in my experience very robust and fast. I've been writing a lot of scrapers along the years and the best combination I found so far is requests / lxml.html / gevent. It doesn't get any simpler than this IMO http://pastebin.com/hacxmAjV
For fun here's the Ruby+Nokogiri version and my attempt at the Clojure+Enlive version (3rd day learning Clojure). https://gist.github.com/danneu/5131596
Re: Web Scraping 101 with Python
#77PyQuery is pretty awesome ( https://pypi.python.org/pypi/pyquery ) Using Requests to download the document, pump it into PyQuery and you can use any jQuery style selectors to get text, attributes and all sorts of other stuff. Example; Here's how to scrape the hacker news homepage https://gist.github.com/samarudge/035ab8aaca224415cb49 (that code could probably be improved but I only spent a couple of minutes on it)
Especially since you can use a Chrome or FFX plugin to inject jQuery into any webpage and then refine your selector via the JavaScript console.
All you need to do then is to copy the selector in your python script and you are done.
Re: Web Scraping 101 with Python
#78Re: Web Scraping 101 with Python
#79For the pythonistas: what is the relationship between BeautifulSoup, lxml, urllib*, scrapy and mechanize?
Here are my highly opinionated opinions about their respective use cases: * BeautifulSoup: It was the best scraping library ever until python-lxml came around and stole the show. Despite that the manual said BeautifulSoup gives you unicode, damnit! it had some long-standing bugs which it gave you strings or incorrectly decoded web pages. I wouldn't use it anymore because lxml is strictly superior. * lxml: The king of…
Admittedly writing this from scratch requires learning the framework, but being able to share and reuse code is a huge win (disclaimer: I'm a Scrapy contributor).
Re: Web Scraping 101 with Python
#80Earlier quoted context omitted.
Mechanize is far and away the best and easiest way to scrape with Ruby until anything is rendered in javascript, which is explicitly not supported. I tend to use Mechanized until I can't, then switch to Watir. Over time, I've found myself just strait up picking up Watir as it runs your browser directly and supports javascript rendering as a result.
How is performance with Watir? With casperjs a page takes me on an avg. 5-10 secs. to process.