- 前一段時間有個課程需要問卷星搜集材料資訊,,但是問卷星這東西你不一個個求人哪有人愿意點進去幫你填呢,,呵呵,不行,我自己來,,,
- 本來想看看問卷星他的表單提交的請求方式,,奈何我太垃圾,看不懂那么龐大的js,理不清其中的思路,,既然能力不行,那只好用selenium這個自動化工具了,
-
很多人學習python,不知道從何學起,
很多人學習python,掌握了基本語法過后,不知道在哪里尋找案例上手,
很多已經做案例的人,卻不知道如何去學習更加高深的知識,
那么針對這三類人,我給大家提供一個好的學習平臺,免費領取視頻教程,電子書籍,以及課程的源代碼!??¤
QQ群:623406465
先用簡單的一個表單做說明吧,找一個簡單的問卷
- 觀察dom樹結構發現這個rel屬性可以確定唯一,那么可以直接用css選擇器語法 a[rel=‘q1_2’]python字串可以用單引號表示,外面套雙引號時候不用考慮轉義字串,比較方便,
- 既然找個這個位置,就可以用程式先模擬點擊了,查看中不中,貼上程式代碼:
from selenium import webdriver import time browser = webdriver.Chrome()#宣告 browser.get('https://www.wjx.cn/jq/31521246.aspx') time.sleep(2) for i in range(10): browser.get('https://www.wjx.cn/jq/31521246.aspx') browser.find_element_by_css_selector("a[rel='q1_3']").click() time.sleep(1) browser.find_element_by_css_selector("a[rel='q2_1']").click() time.sleep(1) browser.find_element_by_css_selector("a[rel='q3_2']").click() time.sleep(1) browser.find_element_by_id("submit_button").click()
有需要注意的是一定要注意時間間隔,稍微一塊就驗證碼伺候,
- 之所以用chromediver是因為有界面的可以知道對錯,當程式無誤的時候可以換成phantomjs,另外,你可以根據已經有的回答情況,和實際情況,按照一定概率進行點擊不同的選項,那么就可以更逼真的實作資料的(偽造)??
- 這篇純粹娛樂,如大佬能直接破解js請賜教,
- 如果沒有selenium或者沒有無頭瀏覽器/chromedriver環境可以百度進行先安裝,
問卷網:
分析結構之后發現和問卷星的不一樣,并且還有多選框,多選框不能為空,我該如何處理呢?
首先,我將我的問卷給我的好哥們姐們認真的填了一下,采集了14份左右的真實樣本, - 這樣我就可以根據這個資料模擬出很逼真的概率,
- 說一下這里不一樣的地方,這里多個元素用selenium中的find_elements查找多個元素,因為這里不好找到唯一標識,只好通過位置確定元素,
下面附上python代碼,核心思想就是如果差不多就隨機編號,如果差得多jiuyong隨機100個數查找百分比的范圍
from selenium import webdriver import time import random browser = webdriver.PhantomJS() browser.get('https://www.baidu.com') time.sleep(2) for i in range(200): try: time.sleep(5) browser.get('https://www.wenjuan.com/s/2Uf6Fbe/') sex=browser.find_elements_by_css_selector("a[rel='question_5bfe34cd92beb5077b5fdaec']") index=random.randint(1,5) if index<3: sex[1].click() else: sex[0].click() time.sleep(0.5) grade=browser.find_elements_by_css_selector("a[rel='question_5bfe34cd92beb5077b5fdaed']") #index=random.randint(0,3) grade[2].click() time.sleep(0.5) istanguo=browser.find_elements_by_css_selector("a[rel='question_5bfe34ce92beb5077b5fdaee']") index=random.randint(1,10) if index>6: istanguo[0].click() else: istanguo[1].click() tiaojian=browser.find_elements_by_css_selector("a[rel='question_5bfe34ce92beb5077b5fdaf1']") index=random.randint(1,13) if index<=6: tiaojian[0].click() index = random.randint(1, 13) if index<=6: tiaojian[1].click() index = random.randint(1, 13) if index <= 3: tiaojian[2].click() if index<=8: tiaojian[3].click() index = random.randint(1, 13) if index<=3: tiaojian[4].click() index = random.randint(1, 13) if index <= 7: tiaojian[5].click() if index<=6: tiaojian[6].click() index = random.randint(1, 13) if index<=9: tiaojian[7].click() index = random.randint(1, 13) if index <= 9: tiaojian[8].click() if index<=2: tiaojian[9].click() index = random.randint(1, 13) if index<=2: tiaojian[10].click() index = random.randint(1, 16) if index <= 2: tiaojian[11].click() index = random.randint(1, 13) if index <= 8: tiaojian[12].click() age= browser.find_elements_by_css_selector("a[rel='question_5bfe34ce92beb5077b5fdaf4']") index=random.randint(0,100) if index<50: age[0].click() elif index>65: age[2].click() else: age[1].click() time.sleep(0.5) yingxiang=browser.find_elements_by_css_selector("a[rel='question_5bfe34ce92beb5077b5fdafb']") index=random.randint(1,10) jud=False if(index<=4): yingxiang[0].click() jud=True index = random.randint(1, 10) if (index <= 2): yingxiang[1].click() jud = True index = random.randint(1, 10) if (index <= 6): jud = True yingxiang[2].click() index = random.randint(1, 10) if (index <= 8): yingxiang[3].click() jud = True index = random.randint(1, 10) if (index <= 5): yingxiang[4].click() jud = True if jud==False:#防止運氣不好一個沒選上 yingxiang[2].click() time.sleep(0.3) jichu=browser.find_elements_by_css_selector("a[rel='question_5bfe34ce92beb5077b5fdafd']") index=random.randint(0,100) if index<64: jichu[1].click() elif index>98: jichu[2].click() else: jichu[0].click() time.sleep(0.5) jiehun=browser.find_elements_by_css_selector("a[rel='question_5bfe395992beb5238625321e']") index=random.randint(0,100) if index<65: jiehun[2].click() elif index>98: jiehun[0].click() elif index>=65 and index<=83: jiehun[3].click() else: jiehun[1].click() browser.find_element_by_id("next_button").click() except Exception as e: print(e) #input.clear() #button = browser.find_element_by_class_name('btn-search') #button.click()
查看無誤之后不想彈出視窗將chromedriver換成phantomjs或設定不跳出引數即可即可,
可以看到答題人數上漲了(切記控制速度)
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/185756.html
標籤:其他
