Python中文
首页
教程
问答
标签
搜索
登录
注册
在python中,使用相对xpath查找给定tex之后的第一个表
回答此问题可获得
20
贡献值,回答如果被采纳可获得
50
分。
<p>我试图找到一个相对(而不是绝对)Xpath,它允许我在文本“<strong>分割时间</strong>”之后导入<strong>第一个</strong>表。这是我的密码:</p> <pre><code>from lxml import html import requests ResultsPage = requests.get('https://www.iaaf.org/competitions/iaaf-world-championships/iaaf-world-championships-london-2017-5151/results/men/10000-metres/final/result') ResultsTree = html.fromstring(ResultsPage.content) ResultsTable = ResultsTree.xpath(("""//*[text()[contains(normalize-space(), "SPLIT TIMES")]]""")) print ResultsTable </code></pre> <p>我试图找到Xpath,它将在“SPLIT TIMES”表中磨练,该表在这里<a href="https://www.iaaf.org/competitions/iaaf-world-championships/iaaf-world-championships-london-2017-5151/results/men/10000-metres/final/result" rel="nofollow noreferrer">https://www.iaaf.org/competitions/iaaf-world-championships/iaaf-world-championships-london-2017-5151/results/men/10000-metres/final/result</a>找到,如下图所示。你知道吗</p> <p>如果Xpath能尽可能多用,我将不胜感激。例如,这个要求可能会改变,所以我会在文本后面找到第一个表,上面写着“10000米男子”(与上面的url相同)。或者,我可能需要找到文本后面的第一个表,该表的内容为'MEDAL table'(不同的url):<a href="https://www.iaaf.org/competitions/iaaf-world-championships/iaaf-world-championships-london-2017-5151/medaltable" rel="nofollow noreferrer">https://www.iaaf.org/competitions/iaaf-world-championships/iaaf-world-championships-london-2017-5151/medaltable</a></p> <p><a href="https://i.stack.imgur.com/8ym56.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/8ym56.png" alt="enter image description here"/></a></p>
0 条评论
分类:
Python问答
请先
登录
后评论
默认排序
时间排序
1 个回答
匿名
1天前
擅长:python、mysql、java
<p>可以通过xpath使用<code>following</code>,如下所示。你知道吗</p> <pre><code>relative_string = "Split times" ResultsTable = ResultsTree.xpath("//*[text()[contains(normalize-space(), '"+relative_string+"')]]/following::table") </code></pre>
请先
登录
后评论
针对此问题:
更多的回答
关注
89
关注
收藏
1
收藏,
216
浏览
网友 提问于 2天前
相关Python问题
如何合并多个PDF文件?
7 回答
如何合并多个xarray数据变量及其坐标?
2 回答
如何合并多个列中具有重复值的行
6 回答
如何合并多个唯一id
9 回答
如何合并多个图纸并使用图纸名称的名称重命名列名?
4 回答
如何合并多个字典并添加同一个键的值?(Python)
8 回答
如何合并多个搜索结果文件(pkl)以将它们全部打印在一起?
7 回答
如何合并多个数据帧
5 回答
如何合并多个数据帧并使用Pandas为假人添加列?
6 回答
如何合并多个数据帧并按时间戳排序
3 回答
如何合并多个数据帧的列表并用另一个lis标记每列
10 回答
如何合并多个数据框中的列
7 回答
如何合并多个文件?
8 回答
如何合并多个查询集?
6 回答
如何合并多个绘图?
3 回答
如何合并多个词典
6 回答
如何合并多个输入数据集(数据帧)?
2 回答
如何合并多条记录中拆分的文本行
1 回答
如何合并多索引列datafram
8 回答
如何合并多级(即多索引)数据帧?
7 回答