如何使用python从多个ul标签中获取id列表?

问题描述 投票:0回答:2

在这里,我想在给定的图片中使用python在列表中的红色框中标记所有ID。这个ID也是随机的,动态的!

enter image description here

python selenium web-scraping beautifulsoup automation
2个回答
0
投票

您可以搜索ul标记并循环搜索,然后获取元素的属性。

elements=driver.find_elements_by_css_selector("ul.plan-card-blue")
id_list=[]
for ele in elements:
    id_list.append(ele.get_attribute("id"))

0
投票

从浏览器中提取所有ul项

   links = browser.find_elements_by_tag_name("ul")

循环列表并获取id值

  for element in links
         idValue = element.get_attribute("id") 

想要将它保存在数组中使用它

 idValue=[]
  for element in links:
         idValue.append(element.get_attribute("id")) 
© www.soinside.com 2019 - 2024. All rights reserved.