[英]Find element by Xpath. How to split the element I don't want inside the Xpath
[英]I want to find the XPATH of an element by knowing it's value
这是我的代码:
def start_server(server_ip = None):
content = driver.page_source
root = html.fromstring(content)
tree = root.getroottree()
result = root.xpath('//*[. = "MythicalNoobsSMP"]')
print(root,tree,result,end="\n")
start_server('MythicalNoobsSMP')
我基本上想从 aternos.org 找到,我想打开函数参数请求的服务器配置文件。 就像这里是我的服务器列表: - 我想基本上打开 MythicalNoobsSMP 服务器,那么我如何获得它的 XPATH? (注意,我不想从开发工具中获取它→检查)
所以你已经有这个权利了?
result = root.xpath('//*[. = "MythicalNoobsSMP"]')
一旦你需要检查它是什么类型的元素。 如果它是一个span
或a
。
然后基本上你可以通过说创建一个通用的 xpath
//elementname[text()='Your specific text']
例如,要查找值为“MythicalNoobsSMP”的span
:
//span[text()='MythicalNoobsSMP']
这将适用于所有未来的参考
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.