用xpath查找跨度值

时间:2018-07-04 15:39:09

标签: python xpath

我正在关注this 登录后从网站抓取信息的教程。 现在,部分代码利用xpath变量来抓取特定内容。我不熟悉xpath,经过大量搜索,我找不到合适的解决方案。我希望你们中的一个能帮助我!

我需要"price" <span>中的值:

<div class="price-box">
<span class="regular-price" id="product-price-64">
<span class="price">€&nbsp;4,90</span>
</span>
</div>

我现在的代码是:

# Scrape url
result = session_requests.get(URL, headers = dict(referer = URL))
tree = html.fromstring(result.content)
bucket_names = tree.xpath("//span[@class='price']/text()")

<span>内获取信息的xpath代码应该是什么?

编辑:根据注释,确实确实没有通过初始页面源。

2 个答案:

答案 0 :(得分:0)

您的xpath看起来差不多,也许您忘了一个点?

bucket_names = tree.xpath(".//span[@class='price']/text()")

答案 1 :(得分:0)

请检查xpath子方法, 您的xpath似乎正确。

尝试使用:<connectionStrings> <add name="dbx" connectionString="Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\db\Database.mdf;Integrated Security=True;MultipleActiveResultSets=True;ApplicationIntent=ReadWrite" providerName="System.Data.SqlClient" /> </connectionStrings>