gpt4 book ai didi

带有 Selenium 的 Python : how to get the first string in element

转载 作者:太空宇宙 更新时间:2023-11-04 00:37:36 27 4
gpt4 key购买 nike

HTML:

<td rowspan="2" class="en">17-04-10<br>00:30</td>

Python代码:

lb3 = driver.find_element_by_xpath("//td[@rowspan='2']")
print (lb3.text)

结果是:

 17-04-10
00:30

我想要像这样的字符串格式 17-04-10 00:30 ,或者只是获取日期 17-04-10 因为我需要修道datetime 对象。

最佳答案

传统上你可能需要使用

//td[@rowspan='2']/text()[1]

得到17-04-10,但是selenium不支持这种语法,所以你可以像下面这样用Python处理输出:

print (lb3.text.split()[0])

获取 17-04-10

print(" ".join(lb3.text.split()))

获取 17-04-10 00:30

关于带有 Selenium 的 Python : how to get the first string in element,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43315075/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com