1.下载插件文件stealth.min.js 链接:https://pan.baidu.com/s/18XV6ROkSg-FEnADyY6AHeA 提取码:bpee 2.自动填写过程中发现挂梯子不用弹出滑动验证,用本地ip刷到几十份就挂了 3.代码
from selenium.webdriver.support.ui import WebDriverWait
import time
import random
from selenium.webdriver import Chrome
from selenium.webdriver.chrome.options import Options
def get_ele_time(driver,time,func):
WebDriverWait(driver,time).until(func)
def run():
chrome_options = Options()
chrome_options.add_argument("--disable-blink-features=AutomationControlled")
chrome_options.add_experimental_option('excludeSwitches', ['enable-automation'])
chrome_options.add_argument(
'user-agent=Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.82 Safari/537.36')
browser = Chrome(options=chrome_options)
with open('D:\Afjy\爬虫\模拟请求/stealth.min.js') as f:
js = f.read()
browser.execute_cdp_cmd("Page.addScriptToEvaluateOnNewDocument", {
"source": js,
})
browser.get('https://www.wjx.cn/vm/YsK8J1l.aspx')
randomId = random.randint(1, 2)
js = "document.getElementById(\"q1_" + str(randomId) + "\").click()"
browser.execute_script(js)
time.sleep(1)
randomId = random.randint(2, 3)
js = "document.getElementById(\"q2_" + str(randomId) + "\").click()"
browser.execute_script(js)
time.sleep(1)
randomId = random.randint(1, 4)
js = "document.getElementById(\"q3_" + str(randomId) + "\").click()"
browser.execute_script(js)
time.sleep(1)
randomId = random.randint(1, 3)
js = "document.getElementById(\"q4_" + str(randomId) + "\").click()"
browser.execute_script(js)
time.sleep(1)
randomId1 = random.randint(1, 6)
js = "document.getElementById(\"q5_" + str(randomId1) + "\").checked = true"
browser.execute_script(js)
js = "document.getElementById(\"q5_" + str(randomId1) + "\").click()"
browser.execute_script(js)
randomId = random.randint(1, 2)
js = "document.getElementById(\"q6_" + str(randomId) + "\").click()"
browser.execute_script(js)
time.sleep(1)
randomId = random.randint(1, 4)
js = "document.getElementById(\"q8_" + str(randomId) + "\").click()"
browser.execute_script(js)
time.sleep(1)
randomId = random.randint(1, 3)
js = "document.getElementById(\"q9_" + str(randomId) + "\").click()"
browser.execute_script(js)
time.sleep(1)
js = "document.getElementById(\"q10_" + str(1) + "\").click()"
browser.execute_script(js)
block = ['1', "2", "1.5"]
randomId = random.randint(0, 2)
browser.find_element_by_id("tqq10_1").send_keys(block[randomId])
time.sleep(1)
randomId1 = random.randint(1, 4)
js = "document.getElementById(\"q11_" + str(randomId1) + "\").checked = true"
browser.execute_script(js)
js = "document.getElementById(\"q11_" + str(randomId1) + "\").click()"
browser.execute_script(js)
randomId1 = random.randint(1, 4)
js = "document.getElementById(\"q12_" + str(randomId1) + "\").checked = true"
browser.execute_script(js)
js = "document.getElementById(\"q12_" + str(randomId1) + "\").click()"
browser.execute_script(js)
randomId1 = random.randint(1, 5)
js = "document.getElementById(\"q13_" + str(randomId1) + "\").checked = true"
browser.execute_script(js)
js = "document.getElementById(\"q13_" + str(randomId1) + "\").click()"
browser.execute_script(js)
randomId1 = random.randint(1, 4)
js = "document.getElementById(\"q14_" + str(randomId1) + "\").checked = true"
browser.execute_script(js)
js = "document.getElementById(\"q14_" + str(randomId1) + "\").click()"
browser.execute_script(js)
js = "document.getElementById(\"q15_" + str(1) + "\").click()"
browser.execute_script(js)
time.sleep(1)
randomId1 = random.randint(1, 2)
js = "document.getElementById(\"q16_" + str(randomId1) + "\").checked = true"
browser.execute_script(js)
js = "document.getElementById(\"q16_" + str(randomId1) + "\").click()"
browser.execute_script(js)
js = "document.getElementById(\"q17_" + str(1) + "\").click()"
browser.execute_script(js)
time.sleep(1)
randomId1 = random.randint(1, 6)
js = "document.getElementById(\"q18_" + str(randomId1) + "\").checked = true"
browser.execute_script(js)
js = "document.getElementById(\"q18_" + str(randomId1) + "\").click()"
browser.execute_script(js)
js = "document.getElementById(\"q19_" + str(1) + "\").click()"
browser.execute_script(js)
time.sleep(1)
randomId1 = random.randint(1, 5)
js = "document.getElementById(\"q20_" + str(randomId1) + "\").checked = true"
browser.execute_script(js)
js = "document.getElementById(\"q20_" + str(randomId1) + "\").click()"
browser.execute_script(js)
block = ["问卷内容还有点不够细致", "问卷内容很全面,符合实际", "没有不足之处,挺好的"]
randomId = random.randint(0, 2)
browser.find_element_by_id("q21").send_keys(block[randomId])
js = "document.getElementById(\"ctlNext\").click()"
browser.execute_script(js)
time.sleep(1)
js = 'document.getElementById("alert_box").style.display="none";'
browser.execute_script(js)
browser.find_element_by_xpath("//div[@id='rectMask']").click()
time.sleep(7)
browser.quit()
if __name__ == "__main__":
for i in range(1,70):
print(i)
run()
time.sleep(2)
|