如何在<span class =“属性优先”>作者:</span> Stepfen King之间抓取内容

时间:2017-11-19 08:19:10

标签: xpath

我有以下来源:

<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)

怎么做?

1 个答案:

答案 0 :(得分:0)

您需要p的文字,而不是span。尝试:

//p[@class="byline"]/text()[2]

//span[@class="attribute first"]/following-sibling::text()[1]