从scrapy.selector导入选择器错误

从scrapy.selector导入选择器错误,第1张

从scrapy.selector导入选择器错误

尝试改为导入HtmlXPathSelector。

    from scrapy.selector import HtmlXPathSelector

然后使用.select()方法解析出你的html。例如,

    sel = HtmlXPathSelector(response)    site_names = sel.select('//ul/li')

示例将如下所示:

    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

希望这可以帮助!



欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/4929658.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-11-12
下一篇 2022-11-12

发表评论

登录后才能评论

评论列表(0条)

保存