【发布时间】:2017-09-01 18:02:06
【问题描述】:
这是一段 HTML,我想从中提取信息:
<li>
<p><strong class="more-details-section-header">Provenance</strong></p>
<p>Galerie Max Hetzler, Berlin<br>Acquired from the above by the present owner</p>
</li>
我想要一个 xpath 表达式来提取第二个 <p> ... </p> 的内容,这取决于之前是否有 <p> ... Provenance ... </p> 的兄弟姐妹
这是我到目前为止的位置:
if "Provenance" in response.xpath('//strong[@class="more-details-section-header"]/text()').extract():
print("provenance = yes")
但是我怎么去Galerie Max Hetzler, Berlin<br>Acquired from the above by the present owner?
我试过了
if "Provenance" in response.xpath('//strong[@class="more-details-section-header"]/text()').extract():
print("provenance = yes ", response.xpath('//strong[@class="more-details-section-header"]/following-sibling::p').extract())
但我得到[]
【问题讨论】:
标签: python-3.x xpath web-scraping scrapy