标签:selenium html random div pre source tools options ble
import re
import requests
import time
import random
from selenium import webdriver
from tools.headers import headers
for item in range(1, 100):
time.sleep(random.randint(5, 10))
url = f‘http://www.xiladaili.com/gaoni/{item}/‘
print(f‘----------------------第{item}页-------------------------‘)
option = webdriver.ChromeOptions()
option.add_argument(‘headless‘) # 设置option
driver = webdriver.Chrome(options=option) # 调用带参数的谷歌浏览器
driver.get(url)
html = driver.page_source
# print(html)
for i in range(1, 51):
time.sleep(random.randint(1, 3))
IP = driver.find_element_by_xpath(f‘/html/body/div/div[3]/div[2]/table/tbody/tr[{i}]/td[1]‘).text
print(IP)
标签:selenium html random div pre source tools options ble
原文地址:https://www.cnblogs.com/wolvies/p/14871876.html