Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use python to complete college brushing courses

2025-04-20 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Network Security >

Share

Shulou(Shulou.com)05/31 Report--

This article is about how to use python to complete college brushing classes. The editor thinks it is very practical, so I share it with you. I hope you can get something after reading this article.

0x01:

First of all, analyze how it verifies that you have finished this class.

This request will be issued when the study is completed.

Then look at where the requested data is generated at the front end.

After a search, I saw that it was function finishWxCourse () under wx.js. The console execution of finishWxCourse () will indeed initiate a request to complete the course.

0x02:

And then the rest is that the idea of the script is to first get the link to the course, and then open it and then execute js finishWxCourse (), and then it turns out that requests is not very good at executing js, and then I followed the advice of several masters and used selenium.... So I wrote while I was learning. I encountered a few small pits.

It would be nice to install many tutorials on the Internet, chromedriver, in environment variables, such as python environment variables. If you encounter problems, you can leave comments.

First of all, the overall idea of the code is to open the website-set cookie---- and then open all hidden elements by clicking-back-click to open all hidden elements-- location click-- back. Then repeat the previous steps

This is simply launching the browser and initiating the request driver = webdriver.Chrome ("C:/Python27/chromedriver.exe") driver.get ("http://wb.mycourse.cn/")" removes all cookie and sets cookie. I log in manually and then add one more thing to remember, that is, I have to request a web page before I can set up cookie and then request a web page driver.add_cookie ({'name':'JSESSIONID','value':'93BEC0FDEF428F98DA1F69A6B3C2BF88'}) # has expired, masters driver.add_cookie ({' name':'acw_tc','value':'7b39758715392684428742395e7ed4b94ed4e9616cb11d4b9df9e244ec7573'}) driver.add_cookie ({'name':'SERVERID') 'value':'02cc313090e3650844ab417ac43bf774 | 1539357767 | 1539357719'}) driver.get ("http://wb.mycourse.cn/svnweiban/student/study_studyAndTest.action") then locates the elements first to see the course link we want to click on."

You can see that there is a pit in the class property where multiple class attributes cannot be located directly by multiple class, otherwise they will be found if they all need to be located together using css. To link and I'm using the name courseLink location here, and it's obvious what it does. Then I also found that 98 courses can be located in the first few class can be located in more than 1000.

Link2s = driver.find_elements_by_class_name ("courseLink") I was happy to think that I was almost done and ready to write a code like this for i in range (99): link2s = driver.find_elements_by_class_name ("courseText") Link2s [I]. Click () driver.execute_script ("finishWxCourse ()")

But it turns out that I can't get the element, and then I keep reporting an error. Baidu found that it didn't expand the element is diplay:none. Hidden, and then the method I found after Baidu has been to change none to block by executing js and found it difficult to locate.

The class attribute is not unique, and it hurts very much. Later, the master recommended that we use xpath to locate, but many people didn't want to give up the trouble. After taking a shower, we found that we could automatically expand the list by locating the element and then clicking on the element.

Through the previous screenshot of the cursorPointer can successfully locate more than 20 places out, but the first few positioning is what the home page search is not what we want. Let's just delete these locations.

Blockclass = driver.find_elements_by_class_name ("cursorPointer") del blockclass [0] for blockc in blockclass: blockc.click ()

Just delete a few locations.

Then, after debugging, the assembly code ran and found several problems at once, the first of which was when

Driver.execute_script ("finishWxCourse ()") # executes js code

After executing the code, you will alert a window to say that you have completed the course. Then it will cause selenium not to click back to face Baidu after programming.

Dig_alert = driver.switch_to.alert # search pop-up window dig_alert.accept () # Click OK

And then there's the last one, after the driver.back (), after the egg hurts, the location before the back will fail, so it can only be repositioned every time, and it's important to note that it takes a second to time sleep before the request is completed, or the next step will lead to an error report, and it will be done in the end.

The complete code is posted below

# coding=utf-8

From selenium import webdriver

Import time

Def login ():

Driver = webdriver.Chrome ("C:/Python27/chromedriver.exe")

Driver.get ("http://wb.mycourse.cn/")"

Driver.delete_all_cookies ()

Driver.add_cookie ({'name':'JSESSIONID','value':'93BEC0FDEF428F98DA1F69A6B3C2BF88'}) # cookie is out of date. No need to try.

Driver.add_cookie ({'name':'acw_tc','value':'7b39758715392684428742395e7ed4b94ed4e9616cb11d4b9df9e244ec7573'})

Driver.add_cookie ({'name':'SERVERID','value':'02cc313090e3650844ab417ac43bf774 | 1539357767 | 1539357719'})

Driver.get ("http://wb.mycourse.cn/svnweiban/student/study_studyAndTest.action")"

Blockclass = driver.find_elements_by_class_name ("cursorPointer")

Del blockclass [0]

Del blockclass [0]

Del blockclass [0]

For blockc in blockclass:

Blockc.click ()

For i in range (99):

Link2s = driver.find_elements_by_class_name ("courseText")

Link2s.click ()

Driver.execute_script ("finishWxCourse ()")

Time.sleep (1)

Dig_alert = driver.switch_to.alert

Dig_alert.accept ()

Driver.back ()

Time.sleep (1)

Blockclass = driver.find_elements_by_class_name ("cursorPointer")

Del blockclass [0]

Del blockclass [0]

Del blockclass [0]

For blockc in blockclass:

Blockc.click ()

Time.sleep (0.5)

Login ()

The above is how to use python to complete college brushing courses. The editor believes that there are some knowledge points that we may see or use in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Network Security

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report