資源簡介
python爬蟲實現(xiàn)自動填寫問卷,具體使用介紹:https://blog.csdn.net/weixin_43863744/article/details/106166713
代碼片段和文件信息
from?selenium?import?webdriver
import?random
import?time
option?=?webdriver.ChromeOptions()
option.add_argument(‘headless‘)
url?=?‘https://www.wenjuan.com/s/yYFBf2I/‘
t?=?200
#?設置提交問卷次數(shù)
path=r“E:\PyCharm_workspace\pachong_1\chromedriver.exe“
for?times?in?range(t):
????driver?=?webdriver.Chrome(executable_path=pathoptions=option)
????driver.get(url)
????#?定位所有的問卷問題
????questions?=?driver.find_elements_by_css_selector(‘.matrix‘)
????for?indexanswers?in?enumerate(questions):
????????#?定位所有問卷問題選項
????????answer?=?answers.find_elements_by_css_selector(‘.icheckbox_div‘)
????????#?定位需要填寫文字的選項,并填入相關內(nèi)容
????????#?if?not?answer:
????????#?????blank_potion?=?answers.find_element_by_css_selector(‘.blank.option‘)
????????#?????blank_potion.send_keys(‘沒有‘)
????????#?????continue
????????if?index?==?3?or?index==4:
????????????choose_ans=a
評論
共有 條評論