【问题标题】:Scrapy - How to get XPATH node as textScrapy - 如何将 XPATH 节点作为文本获取
【发布时间】:2017-06-10 05:49:11
【问题描述】:

我想从 XHTML 节点中获取一个节点作为字符串。

例如

<html>
    <body>
        <div>
            <input type="text" value="myText"></input>
            <input type="text" value="myText" disabled="true"></input>
        </div>
    </body>
</html>

我想得到两个输入的 XHTML 文本作为数组中的字符串,像这样?

["<input type="text" value="myText"></input>"
"<input type="text" value="myText" disabled="true"></input>"]

scrapys XPATH 选择器可以做到这一点吗?

【问题讨论】:

    标签: python xpath scrapy


    【解决方案1】:

    不完全是您所要求的,因为它只显示开始标签,并且由于某种原因,它会从最后一个输入中删除 ="true",但根据您使用它的目的,它可能就足够了。

    >>> response.xpath('//div/input').extract()
    [u'<input type="text" value="myText">', u'<input type="text" value="myText" disabled>']
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-12-25
      • 1970-01-01
      • 1970-01-01
      • 2012-12-30
      • 1970-01-01
      • 1970-01-01
      • 2011-09-23
      相关资源
      最近更新 更多