代わりにHtmlXPathSelectorをインポートしてみてください。
from scrapy.selector import HtmlXPathSelector
そして、.select()メソッドを使用して html を解析します。例えば、
sel = HtmlXPathSelector(response)
site_names = sel.select('//ul/li')
Scrapy サイト ( http://doc.scrapy.org/en/latest/intro/tutorial.html ) のチュートリアルに従っている場合、更新された例は次のようになります。
from scrapy.spider import BaseSpider
from scrapy.selector import HtmlXPathSelector
class DmozSpider(BaseSpider):
name = "dmoz"
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):
sel = HtmlXPathSelector(response)
sites = sel.select('//ul/li')
for site in sites:
title = site.select('a/text()').extract()
link = site.select('a/@href').extract()
desc = site.select('text()').extract()
print title, link, desc
お役に立てれば!