#Disclaimer
This article is only used for a reference while learning Python. The author is not responsible for illegal activities carried out by readers through the same method.
#Introduction
There are all kinds of perfect auto WJX filling programmes on platforms such as GitHub. However, I found that most of the relevant articles meet the following conditions:
- Options that can only be chosen randomly
- The methods are too complicated
- The programmes can be used no more
But I decided to develop an auto-filling programme on my own to finish the WJX quickly, and WJX Solver V1 that was developed the earliest came out. The idea for this version was based on a keyboard experience, and it controls the keyboard to complete by invoking the third-party library pynput.
Through practice, the programme of this version could submit a questionnaire with WJX dozens of tens of questions almost instantly (without Smart Captcha, not considering elapsed time before the programme runs).
However, the "Random Order of Options" feature broke the illusion of the past。
How can we solve the problem?
#Preperations
#Dowmload the browser
I suggest using Microsoft Edge of a newer version, Google Chrome (or Chromium), Firefox.
If you use macOS High Sierra (or newer versions), you can also use Safari that is more convenient. If you use Linux, please do not use Microsoft Edge.
#Check the version of the browser
If you use macOS High Sierra (or newer versions) and Safari, please skip this section.
If you use Microsoft Edge or Google Chrome (or Chromium), you can check the version by opening edge://version/
or chrome://version/
; if you use Firefox, please refer to Find What Version Firefox You Are Using.
#Download the browser driver (WebDriver)
If you use macOS High Sierra (or newer versions) and Safari, please skip this section.
Browser | Download Link |
---|---|
Microsoft Edge | https://developer.microsoft.com/en-us/microsoft-edge/tools/webdriver/ |
Google Chrome (or Chromium) | https://chromedriver.chromium.org/downloads/ |
Firefox | https://github.com/mozilla/geckodriver/releases/ |
Safari | N/A |
After downloading the browser driver, you need to add the folder where the browser driver is located to the PATH
environment variable, or move the browser driver to the folder where the PATH
environment variable is added (for example, in the folder where python.exe
is located under Windows).
#Download the third-party library
You can download the third-party libraries pynput and selenium by using pip directly.
|
|
#Get started
#(Optional) Create a questionnaire
Please creat a simple questionnaire to start the following tests. Here is an example.
#Open the questionnaire using Python
All you need to open a web page in a browser is its URL (Uniform Resource Locator), and the same is true in Python. We just need to tell Selenium which browser and URL to use to open the web page. Using Microsoft Edge as an example, the following code opens a sample questionnaire.
|
|
#Get the contents of the questionnaire
Although the results of questionnaires with random order of options are different each time they are opened, still you can get the orders of options by checking HTML codes. In Selenium, you can get the HTML code through browser.page_source
.
After getting the HTML codes, it's not difficult to find out that after getting the HTML codes twice, only the order of the elements corresponding to the options changes, but the elements corresponding to each option always remain the same. In other words, each option also retains its initial number in the form of label for=q{task_id}_{option_id}
. Therefore, everything is clear. What you only need to do is to read the option order after opening the questionnaire, and then follow up on the actual situation and fill out the questionnaire using Pynput. And you only need to use regular expression operations re.
#Match the option order
This section is intended for readers who are not familiar with how to match regular expressions in Python. If you're familiar with the usage, you can skip this section.
The basics of regular expressions are described in detail on some websites, and the design of this programme basically does not require relevant knowledge, so it will not be detailed here.
Based on the experience gained in the previous section, we can write a regular expression that matches the option numbers label for=q(\d+)_(\d+)
. To match all the option numbers, we can use the function re.findall(pattern,string,flags = 0)
. This function will return all non-overlapping matches of the regular expression pattern
in the string string
as a list of string tuples. Therefore, in the example, it'll return lists such as [('2','2'),('2','1'),('2','3')]
.
Once you have the order of the options, you can iterate through the list to find where the answers are.
|
|
#Pass the smart verification
Unluckily, while using this method, we will be identified by WJX. So we need to configure the browser in advance. The configuration method is as follows, but it is not expanded in detail.
|
|
#Done
As a result, the WJX auto-filling procedure is completed.
|
|
#Future
As mentioned in many places above, in the future, the programme will support more question types such as multiple-choice questions.
In addition, in the future, the internal structure may be optimized, and the third-party library dependency may be reduced, and the programme running speed may be improved.
#References
- python监听、操作键盘鼠标库pynput详细教程 - 风吹云动 - 博客园.. https://www.cnblogs.com/tobe-goodlearner/p/tutorial-pynput.html
- Python selenium自动化刷问卷+绕过智能验证_Polaris_T的博客-CSDN博客_python selenium自动填写问卷.. https://blog.csdn.net/qq_45717425/article/details/119737648
- The Selenium Browser Automation Project | Selenium.. https://www.selenium.dev/documentation/
#Copyright
The text and theon-code images in this article are licensed under CC BY-SA 4.0. The code in this article is not copyrighted in any form and is in the PD.