假设我有多个divs
看起来像这样:
<div class="class1">
<div class="class2">
<div class="class3">Text1</div>
<div class="class4">
<a href="https://somelink"><h2>Text2</h2></a>
<p class="class5">Text3 <span class="class6"> Text4 </span></p>
</div>
</div>
</div>
对于每个div
,我可以得到Text1、Text2、Text3和Text4:
elements = driver.find_elements_by_xpath("//div[@class='class1']/*")
for e in elements:
print(e.text)
print('------------------------------------------')
但是我如何额外获得href
的值呢
我希望:https://somelink,Text1,Text2,Text3,Text4
我想你会在这里找到答案:Python Selenium - get href value
基本上,它看起来像
试着这样做:
为什么不这样做呢
相关问题 更多 >
编程相关推荐