【发布时间】:2020-05-18 08:38:22
【问题描述】:
我正在尝试使用 xpath 从首都 wiki 页面中检索国家名称,特别是从城市的主要信息表中。
例如我想从https://en.wikipedia.org/wiki/Barcelona检索“西班牙”
xml format for Barcelona table country row
网址是http://en.wikipedia.org/wiki/Barcelona
import requests
import lxml.html
res = requests.get(url)
doc = lxml.html.fromstring(res.content)
country = doc.xpath("//table[@class='infobox geography vcard']//tr[@class = 'mergedtoprow']//th[contains(text(), 'Country')]/td//a//text()")
没有得到任何结果
谢谢
【问题讨论】:
标签: python-3.x xpath