gpt4 book ai didi

Python Selenium根据id值提取href

转载 作者:行者123 更新时间:2023-12-01 04:03:14 25 4
gpt4 key购买 nike

我正在尝试根据唯一的 id 提取 href 值,其中 p 后面的数字有所不同,但都是数字并以“结尾”

例如 id="p4423234"id="p5547"id="p4124234"id="234"

<a href="/string/string-string.html" class="profile-enable" rel="nofollow" 
id="p1234"> `

`

我可以使用

来 grep p 的值
cat p_id.html | grep "id=\"p[0-9]\+\""

但我无法弄清楚如何在 python selenium 中使用 find_element_by_id 返回 href 值。

预先感谢您的帮助。我是网络抓取新手,但很享受挑战。

最佳答案

返回所有 id 为“p[0-9]+”的元素:

driver.find_elements_by_xpath("//*[starts-with(@id,'p') and substring(@id,2)>=0]")

关于Python Selenium根据id值提取href,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36131378/

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