<span class='python'>
<a>google</a>
<a>chrome</a>
</span>我想得到chrome,并让它像这样工作。
q = item.findall('.//span[@class="python"]//a')
t = q[1].text # first element = 0我想把它组合到一个XPath表达式中,只得到一项,而不是列表。
我试过了,但不起作用。
t = item.findtext('.//span[@class="python"]//a[2]') # first element = 1实际的HTML是这样的,而不是简化的。
<span class='python'>
<span>
<span>
<img></img>
<a>google</a>
</span>
<a>chrome</a>
</span>
</span>https://stackoverflow.com/questions/4117953
复制相似问题