Python 将xpath的结果存储到一个变量中,以帮助将来的查询

Python 将xpath的结果存储到一个变量中,以帮助将来的查询,python,xpath,scrapy,Python,Xpath,Scrapy,我正在使用Scrapy来抓取一些网站。我对Scrapy和XPath都是新手。这个问题正在讨论中 正如问题标题中提到的,我想将所选节点存储在变量中。我想进一步查询,但不是整个html。我只想查询加载的变量。让我解释一下发生了什么 让示例html页面为: <sample> <tag attribute="I NEED THIS"> <common1> Area to be processed first

我正在使用Scrapy来抓取一些网站。我对Scrapy和XPath都是新手。这个问题正在讨论中

正如问题标题中提到的,我想将所选节点存储在变量中。我想进一步查询,但不是整个html。我只想查询加载的变量。让我解释一下发生了什么

让示例html页面为:

<sample>
    <tag attribute="I NEED THIS">
        <common1>
            Area to be processed first 
        </common1>
        <common2>
            Area to be processed later
        </common2>  
    </tag>  

    <tag attribute="I DON'T NEED THIS">  
        <common1>
            Not interested in this part    
        </common1>
        <common2>
            Again not interested here
        </common2>
    </tag>
</sample>
后来我做了以下事情:

common1 = needed.select('//common1')

我得到了整个文档中存在的
common1
标记元素,而不仅仅是来自所需的变量。我需要一些帮助。

您需要使用相对xpath:

.//common1

请参阅“刮痧文档”。

哦。。。对对不起,我错过了那部分
.//common1