我有以下来源:
<p class="byline"><span class="attribute first">AUTHOR: </span>Stephen Butts<span class="attribute">DATE: </span><span class="monthText" style="margin-right:4px;">MAY</span>2015<span class="attribute">SUBJECT: </span>Options</p>
我想使用XPath来绘制AUTH的文本/内容:Stephen King。我尝试过使用以下内容但它不起作用:
authors = tree.xpath('//span[@class="attribute first"]/text()', namespaces=ns)
怎么做?
答案 0 :(得分:0)
您需要p
的文字,而不是span
。尝试:
//p[@class="byline"]/text()[2]
或
//span[@class="attribute first"]/following-sibling::text()[1]