24 May'11
Scrapy 0.12 Parsing with python
Based on Scrapy Tutorial (dead link: doc.scrapy.org/intro/tutorial.html)
- Install scrapy and dependencies
sudo apt-get install python-lxml sudo easy_install -U Scrapy
- Create project
scrapy startproject dmoz
- Create item models
from scrapy.item import Item, Field class DmozItem(Item): title = Field() link = Field() desc = Field()
- Create spiders (in projname/spiders/)
from scrapy.spider import BaseSpider from scrapy.selector import HtmlXPathSelector from dmoz.items import DmozItem class DmozSpider(BaseSpider): name = "dmoz.org" allowed_domains = ["dmoz.org"] start_urls = [ "http://www.dmoz.org/Computers/Programming/Languages/Python/Books/", "http://www.dmoz.org/Computers/Programming/Languages/Python/Resources/" ] def parse(self, response): hxs …
Category: 2011