ai didi

python - 使用selenium(python)抓取网页

转载 作者:太空宇宙 更新时间:2023-11-03 16:24:32 24 4
gpt4 key购买 nike

您好,我想废弃下图中选择的内容:

Image Code

我知道我可以使用以下代码来获取文本:

cell = driver.find_elements_by_xpath(".//*[@id='ip_selection1233880116name']") 
print cell.text

但我的问题是 ip_selection1233880116name 应该是动态的,因为正如您从图像中看到的那样,它每次都会发生变化。

我该怎么做?

非常感谢您的帮助!!!!

最佳答案

使用 contains 来捕获假定数字全部发生变化的名称,对于单个元素,您还应该使用 find_element 而不是 find_elements :

find_element_by_xpath("//*[contains(@id,'ip_selection') and contains(@id,'name')]") 

您还可以根据浏览器使用starts-with和ends-with:

find_element_by_xpath("//*[starts-with(@id,'ip_selection') and ends-with(@id,'name')]") 

关于python - 使用selenium(python)抓取网页,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38110108/

24 4 0
文章推荐: php - 自适应支付 IPN 未发送
文章推荐: c# - MvxBind :Error: 10. 40 View 绑定(bind)时抛出异常
文章推荐: c# - 向 getasync 添加内容
文章推荐: python - python 中 sys.platform 的用途是什么?
太空宇宙
个人简介

我是一名优秀的程序员,十分优秀!

滴滴打车优惠券免费领取
滴滴打车优惠券
全站热门文章
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com