gpt4 book ai didi

Python:无法从 webdiver 获取 href

转载 作者:行者123 更新时间:2023-12-01 01:42:48 28 4
gpt4 key购买 nike

<td>
<div class="buy_car_list_img">
<a href="buy_detail.aspx?TSEQNO=5002081">
<img src="http://www.xxxxx.com//UPLOAD/AM/BF5054/26531.jpg" width="100">
</a>
</div>
</td>

我想获取href的url。

buy_detail.aspx?TSEQNO=5002081

代码:

g=driver.find_elements_by_class_name("buy_car_list_img")
#print(g)
for item in g:
print(item.get_attribute('href'))

当我打印此内容时,它返回“无”,任何建议都会受到赞赏。

最佳答案

class 位于没有 href 属性的 div 上。您想要获取 a 标记。试试find_elements_by_css_selector

g = driver.find_elements_by_css_selector('.buy_car_list_img a')

关于Python:无法从 webdiver 获取 href,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51700417/

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