-
Notifications
You must be signed in to change notification settings - Fork 45
Expand file tree
/
Copy pathtest.py
More file actions
46 lines (35 loc) · 1.14 KB
/
test.py
File metadata and controls
46 lines (35 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
from selenium import webdriver
from selenium.webdriver.common.by import By
import time
import random
with open('ip.txt') as f:
lines = (line.strip() for line in f)
ip = list(lines)
with open('user_agent.txt') as f:
lines = (line.strip() for line in f)
user_agent = list(lines)
# http://httpbin.org/get
count = 0
for i in range(len(ip)):
driver = None
try:
# 添加配置
options = webdriver.ChromeOptions()
options.add_argument('User-Agent=' + random.choice(user_agent))
options.add_argument('proxy-server=http://' + ip[i])
# 创建浏览器驱动
driver = webdriver.Chrome(options=options)
driver.get("http://www.baidu.com")
input = driver.find_element(By.CSS_SELECTOR, '#kw')
input.send_keys("如吉生物")
button = driver.find_element(By.CSS_SELECTOR, '#su')
button.click()
# print(driver.page_source)
time.sleep(10)
print(str(count) + 'times')
count = count + 1
driver.quit()
except Exception: # 其他异常
if driver is not None:
driver.quit()
print('Retry')