首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >将lxml转换为scrapy xxs选择器

将lxml转换为scrapy xxs选择器
EN

Stack Overflow用户
提问于 2013-07-25 15:06:18
回答 1查看 121关注 0票数 1

如何将这个纯python转换为xxs选择器中内置的scrapy?这个可以工作,但我想将它转换为scrapy选择器。

代码语言:javascript
复制
    def parse_device_list(self, response):
    self.log("\n\n\n List of devices \n\n\n")
    self.log('Hi, this is the parse_device_list page! %s' % response.url)
    root = lxml.etree.fromstring(response.body)
    for row in root.xpath('//row'):
        allcells = row.xpath('./cell')
        # first cell contain the link to follow
        detail_page_link = allcells[0].get("href")
        yield Request(urlparse.urljoin(response.url, detail_page_link ), callback=self.parse_page)
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-07-25 18:06:22

试试看:

代码语言:javascript
复制
def parse_page(self, response):
    xxs = XmlXPathSelector(response)
    for row in xxs.select('//row'):
        detail_page_link = row.select('.//cell[1]/@href')[0].extract()
        yield Request(urlparse.urljoin(response.url, detail_page_link), callback=self.parse_page)
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/17861781

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档