python如何遍历python如何遍历

获取li标签里面的<a>href和title,使用python 3.4版本

#coding:utf-8
from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.support.ui import WebDriverWait
import time


d = webdriver.Chrome()
d.get('https://www.tapd.cn')
d.maximize_window()
time.sleep(3)
d.find_element_by_link_text('登录').click()
time.sleep(3)
d.find_element_by_id('username').send_keys('[email protected]')
d.find_element_by_id('password_input').send_keys('123456')
d.find_element_by_id('tcloud_login_button').click()

time.sleep(3)

#鼠标移动到对应的图标,显示图标下的所有项目列表

ele = d.find_element_by_xpath("//*[@id='tree-wrapper']/DIV[4]/A/I")
ActionChains(d).move_to_element(ele).perform()

time.sleep(3)

#获取到li下面的所有a标签

s = d.find_elements_by_xpath('[@id="myprojects-list-wrap"]/ul/li/a')
for i in s:
    print (i.get_attribute('title'),i.get_attribute('href'))

d.quit()


相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-12-26
  • 2020-03-23
  • 2021-12-29
  • 2021-10-05
  • 2021-07-23
猜你喜欢
  • 2022-12-23
  • 2021-05-19
  • 2022-12-23
  • 2022-02-25
  • 2022-02-03
  • 2021-06-30
  • 2022-12-23
相关资源
相似解决方案