Web Scraping 101 with Python
gregreda.com
Web Scraping 101 with Python
1–10 of 80 posts
Re: Web Scraping 101 with Python
#2Re: Web Scraping 101 with Python
#3Re: Web Scraping 101 with Python
#4Re: Web Scraping 101 with Python
#5Re: Web Scraping 101 with Python
#6Using 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
#7Re: Web Scraping 101 with Python
#8But why python? Stop now and use perl. Perl's HTTP libraries are actually sane, unlike urllib[2], WWW::Mechanize is brilliant, and it's easier to throw in disgusting hacks in perl when you need them, which is constantly in the business of scraping the web.
Re: Web Scraping 101 with Python
#9This will only be a good approach if you are going to scrape a small amount of pages. The problem is using synchronous requests, as this blocks the crawler until a request has finished. Using asynchronous requests such as supported by twisted (and scrapy) will allow you to crawl a lot faster using the same resources.
Re: Web Scraping 101 with Python
#10This will only be a good approach if you are going to scrape a small amount of pages. The problem is using synchronous requests, as this blocks the crawler until a request has finished. Using asynchronous requests such as supported by twisted (and scrapy) will allow you to crawl a lot faster using the same resources.
This can actually sometimes be a feature. It makes it far less likely to have your IP banned. Its also a far more polite way to crawl someones site.