聪明bo

导航

爬取ac中在线设备

 1 from selenium import webdriver
 2 from selenium.webdriver.common.keys import Keys
 3 import time
 4 chrome_driver = r"chromedriver.exe"
 5 driver = webdriver.Chrome(executable_path=chrome_driver)
 6 driver.get("https://*.*.*.*/index.php/welcome/login")
 7 while True:
 8     try:
 9         driver.find_element_by_id('login_user').send_keys("*")
10     except Exception:
11         continue
12     break
13 driver.find_element_by_id('login_password').send_keys("*")
14 driver.find_element_by_id('sub').click()
15 while True:
16     try:
17         time.sleep(0.5)
18         driver.find_element_by_xpath("//*[@title='无线状态']").click()
19     except Exception:
20         continue
21     break
22 while True:
23     try:
24         time.sleep(0.5)
25         driver.find_element_by_xpath("//button[text()='高级搜索']").click()
26     except Exception:
27         continue
28     break
29 while True:
30     try:
31         time.sleep(0.5)
32         driver.find_element_by_xpath("//*[@name='status']").click()
33     except Exception:
34         continue
35     break
36 while True:
37     try:
38         time.sleep(0.5)
39         driver.find_elements_by_class_name("x-combo-list-item")[1].click()
40     except Exception:
41         continue
42     break
43 while True:
44     try:
45         time.sleep(0.5)
46         driver.find_element_by_xpath("//button[text()='提交']").click()
47     except Exception:
48         continue
49     break
50 while True:
51     try:
52         time.sleep(0.5)
53         driver.find_element_by_xpath("//input[@placeholder='选填']").send_keys(Keys.BACKSPACE)
54         driver.find_element_by_xpath("//input[@placeholder='选填']").send_keys(Keys.BACKSPACE)
55     except Exception:
56         continue
57     break
58 while True:
59     try:
60         time.sleep(0.5)
61         driver.find_element_by_xpath("//div[text()=' 10']").click()
62     except Exception:
63         continue
64     break
65 while True:
66     try:
67         time.sleep(3)
68         num = int(driver.find_element_by_xpath("//div[contains(text(),'/')]").text.split(' ')[2].strip())
69     except Exception:
70         continue
71     break
72 time.sleep(2)
73 for i in range(num):
74     a = driver.find_elements_by_class_name('sf-ico-ap-normal')
75     for x in a:
76         print(x.text.split('_')[0])
77     driver.find_element_by_class_name("x-tbar-page-next").click()
78     time.sleep(2)
79 driver.quit()

 

posted on 2019-08-29 02:53  聪明bo  阅读(112)  评论(0)    收藏  举报