web自動化簡單使用程式碼,獲取集合資料

小磊在努力@發表於2020-10-05

**

web自動化簡單使用程式碼,獲取集合資料

# oding = utf-8
# -*- coding:utf-8 -*-
from selenium import webdriver
import time

web = webdriver.Firefox()
url = "http://www.baidu.com"
web.get(url)
web.find_element_by_id("s-usersetting-top").click()
# diver.find_element_by_partial_link_text("設定").click()
time.sleep(2)
web.find_element_by_xpath(".//*[@id='s-user-setting-menu']/div/a[2]").click()
time.sleep(2)
web.find_element_by_xpath(".//*[@id='adv-setting-gpc']/div/div[1]/i[1]").click()
time.sleep(2)
web.find_element_by_xpath(".//*[@id='wrapper']/div[6]/div/div/ul/li[2]").click()
time.sleep(2)
list = web.find_elements_by_class_name("c-select-item")    #elements是接收一組
print("=======:%s" % list)
print("1234567:%s" % type(list))
for i in list:
    print(i.text)
    if i.text in "最近一天":
        print("11111111111111")
        web.find_element_by_xpath(".//*[@id='wrapper']/div[6]/span/i").click()
        web.close()
        break
time.sleep(2)


相關文章