【发布时间】:2014-03-10 10:47:45
【问题描述】:
请帮助使用 xpath 获取第二个标签的内容。下面是我写的代码。但它不起作用
import lxml.html
doc = lxml.html.document_fromstring("""
<nav class="Paging">
<a href="/women/dresses/cat/4?page=1" class="active">1</a>
<a href="/women/dresses/cat/4?page=2">2</a>
<a href="/women/dresses/cat/4?page=2" rel="next">Next »</a>
</nav>
""")
res = doc.xpath('//nav[@class="Paging"][position() = 1]/a[position() = last() and @rel != "next"]/text()')
print(res)
【问题讨论】: