1500字范文,内容丰富有趣,写作好帮手!
1500字范文 > 超星问卷与麦客问卷自动填写(selenium+Chrome)

超星问卷与麦客问卷自动填写(selenium+Chrome)

时间:2020-12-03 05:23:12

相关推荐

超星问卷与麦客问卷自动填写(selenium+Chrome)

一、超星问卷自动填写

从网上找了很多自动填写的文章,但发现时间比较久远,很多都不能运行,所以自己便写了这篇文章,第一次写文章,不知道该从何说起,下面会直接把代码发布出来,都是近期运行过的,但只限单选、多选、填空。

代理ip与智能检测没有添加进去,但不影响运行,在同一份问卷填写多次后,每隔几份会出现智能验证,我的解决方法是换个无线,我是想添加代理ip的,但不知道为啥,换了很多高匿ip,都显示代理ip失效,如果有人知道错在哪里,可以在评论区回复。

from selenium import webdriverimport randomimport timefrom fake_useragent import UserAgentfor i in range(1):headers = UserAgent().chrome#proxys = ['','','']#proxy = random.choice(proxys)#print(proxy)options = webdriver.ChromeOptions()#添加UserAgentoptions.add_argument('--user-agent={}'.format(headers))#options.add_argument('--proxy-server=http://' + proxy)browser = webdriver.Chrome(options=options)browser.get("问卷地址")answers = browser.find_elements_by_css_selector(".ui-field-contain")for answer in answers:try:browser.execute_script("arguments[0].scrollIntoView();", answer)quions = answer.find_elements_by_css_selector(".ui-radio")quion = answer.find_elements_by_css_selector(".ui-checkbox")ans = answer.find_elements_by_css_selector(".label")#填空题if not ans:text = answer.find_element_by_css_selector("input")text.send_keys('无')continue#单选题if quions:lsans = random.choice(ans)lsans.click()continue#多选题if quion:for i in range(5):lsans = random.choice(ans)lsans.click()continueexcept Exception as e:print(e)am = browser.find_element_by_css_selector("#ctlNext")am.click()browser.quit()time.sleep(1)

注释部分可以忽略

二、麦客问卷自动填写

from selenium import webdriverimport randomimport timefrom fake_useragent import UserAgentfor i in range(1):headers = UserAgent().chrome#proxys = ['']#proxy = random.choice(proxys)#print(proxy)options = webdriver.ChromeOptions()#添加UserAgentoptions.add_argument('--user-agent={}'.format(headers))#options.add_argument('--proxy-server=http://' + proxy)browser = webdriver.Chrome(options=options)browser.get("问卷地址")answers = browser.find_elements_by_css_selector(".fb_component")for answer in answers:try:browser.execute_script("arguments[0].scrollIntoView();", answer)quions = answer.find_elements_by_css_selector(".radio")quion = answer.find_elements_by_css_selector(".checkbox")ans = answer.find_elements_by_css_selector(".fbc_optionsLi")#填空题#if not ans:#text = answer.find_element_by_css_selector("")#text.send_keys('无')#continue#单选题if quions:lsans = random.choice(ans)lsans.click()continue#多选题if quion:for i in range(5):lsans = random.choice(ans)lsans.click()continueexcept Exception as e:print(e)am = browser.find_element_by_css_selector(".fb_submitBtn")am.click()browser.quit()time.sleep(1)

麦客问卷的填空题因为我没有遇到,所以在代码段中填空的选择器我没有填写,可自行添加。

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。