Python selenium automatically fills in the questionnaire star

1. Introduction

The main function of this python script is to automatically fill in questionnaire stars, which is suitable for filling in a large number of questionnaire stars.
Questionnaire has the function of intelligently detecting automated programs, so I added some codes to avoid detection. In addition, Questionnaire also has the function of detecting IP addresses. If you only use the current IP to fill in the questionnaire, it will be easy to be found. To solve this problem, I set up proxy ip camouflage. Questionnaire Star will also detect the time to fill in the questionnaire. Proper use of sleep() can make the completed questionnaire more realistic and effective.

2. Configuration

  1. Google browser automation plug-in , choose the plug-in that suits your browser version to download, and put it in the same directory as the python script.

  2. Proxy IP address
    The following is a website to obtain proxy IP for free: https://www.kuaidaili.com/free/
    Many free proxy IPs are invalid and need to be screened before they can be used .
    I used the following proxy IP
    insert image description here
    to fill out the questionnaire and log in Questionnaire star platform, check the filling records (the IP is somewhat deviated, but it is indeed a successful visit, and the ip address has also changed)
    insert image description here

3. Python script code


import random
from time import sleep
from lxml import html
from my_fake_useragent import UserAgent
from selenium import webdriver
from selenium.webdriver.chrome.options import Options


etree = html.etree

chrome_option = Options()
chrome_option.add_argument('--headless')
chrome_option.add_argument('--disable-gpu')
while True:
    ua = UserAgent(family='chrome')
    #请求头自动随机获取
    user_agent = ua.random()
    headers1 = {
    
    "User-Agent":  user_agent}
    url = 'https://www.wjx.cn/vj/PWcHjHc.aspx'
    # referer = 'https://www.csdn.net/'
    driver_path = 'chromedriver.exe'
    opt = webdriver.ChromeOptions()
    #代理ip伪装,如果要伪装ip需要先找到一个能用的高匿名代理IP,否则页面打不开
    opt.add_argument("--proxy-server=http://14.20.235.139:9797")
    opt.add_experimental_option('excludeSwitches', ['enable-automation'])
    opt.add_experimental_option('useAutomationExtension', False)
    opt.add_argument('--user-agent=%s' % user_agent)
    opt.add_argument('--headers=%s' % headers1)
    # opt.add_argument('--referer=%s' % referer)
    # opt.add_argument('--user-agent=%s' % cookie)
    # 实现无可视化界面
    # opt.add_argument('--headless')
    # opt.add_argument('--disable-gpu')
    # 实现规避检测
    opt.add_experimental_option('excludeSwitches', ['enable-automation'])
    browser = webdriver.Chrome(executable_path=driver_path,options=opt)
    browser.execute_cdp_cmd('Page.addScriptToEvaluateOnNewDocument',
                               {
    
    'source': 'Object.defineProperty(navigator, "webdriver", {get: () => undefined})'})

    #根据问卷设置自动填写样式
    browser.get(url)
    logo = browser.find_element_by_xpath('//*[@id="q1"]').send_keys("你好")
    browser.find_element_by_xpath('//*[@id="q2"]').send_keys("小明")
    i = 3
    while i <= 14:
        c = random.randint(1, 2);
        c1 = '//*[@id="divquestion' + str(i) + '"]/ul/li[' + str(c) + ']/label'
        browser.find_element_by_xpath(c1).click()
        i = i + 1
    browser.find_element_by_xpath('//*[@id="submit_button"]').click()
    browser.find_element_by_xpath('//*[@id="alert_box"]/div[2]/div[2]/div[2]/button').click()
    browser.find_element_by_xpath("//div[@id='captcha']").click()
    sleep(5)
    browser.close()



4. Display of running results

insert image description here

Guess you like

Origin blog.csdn.net/Tom197/article/details/122361835