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 realize automatic Water Army Review

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

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

This article introduces the relevant knowledge of "how to use Python to automate Water Army Review". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

To comment on login, of course, you should be able to log in first, use the requests library to deal with it, and try to see whether you can see your own message list:

Msg_url = "http://msg.csdn.net/"r = requests.get (msg_url, auth= ('drfish',' password')) results jump to the login interface. OK, take a look at how the login interface is logged in and find the form:

Found that there are some hidden parameters, such as lt, excution, etc., and the kind programmer also stated the reason why it cannot be directly authenticated: lack of a serial number, then visit it one more time to obtain the serial number, use BeautifulSoup to analyze the page content to grab the serial number, and introduce session because you need to operate across different domains:

Msg_url = "http://msg.csdn.net/"login_url =" https://passport.csdn.net/"headers = {: 'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) Rv:1.9.1.6) Gecko/20091201 Firefox/3.5.6'} session = requests.session () session.headers.update (headers) r = session.get (login_url) page = BeautifulSoup (r.text, "lxml") authentication = {: "drfish",: "password",: page.select ("[name=lt]") [0] ["value"],: page.select ("[name=execution]") [0] [value "],:" submit " } r = session.post (login_url, authentication) R2 = session.get (msg_url) print (r2.text) Now that you can get my message, it shows that the login problem has been solved successfully, so the automated water army review should be close at hand.

Automatic comments have learned their lesson this time. Pick a random article and check the comment box form:

Submit comments based on the login code above:

Blog_url = "http://blog.csdn.net/u013291394/comment/submit?id=50444369"comment = {:" Water Army comment test ",:" 531203 "} R2 = session.post (blog_url, comment) print (r2.text) result returned {" result ": 0," content ":" comment content is not filled in! " , "callback": null, "data": null}. Interestingly, the parameters should be processed in js. Then pull js out and have a look. Search the js file in the web page. There is a comment.js. This is it. In the above form, you can see that the subform method is called during submission, as shown below:

Function subform (e) {if (c_doing) return false; var content = $.trim ($(editorId). Val ()); if (content = = ") {commentTip (" comment content is not filled in! "); return false;} else if (content.length > 1000) {commentTip (" comment content is too long to exceed 1000 characters! ") ; return false;} var commentId = $("# commentId"). Val (); commentTip ("commenting..."); var beginTime = new Date (); $(editorId) .attr ("disabled", true); $("button [type=submit]", e) .attr ("disabled", true); c_doing = true $.ajax ({type: "POST", url: $(e) .attr ("action"), data: {: commentId,: content,: $("# comment_replyId"). Val (), $("# boleattohome") .val ()}, success: function (data) {c_doing = false CommentTip (data.content); if (data.result) {var rcommentid=$ ("# comment_replyId"). Val () $(editorId) .val (''); $("# comment_replyId,#comment_verifycode") .val (''); commentscount++; loadList (1, true) $(editorId) .attr ("disabled", false); $("button [type=submit]", e) .attr ("disabled", false); commentTip ("published successfully! Comments took time: "+ (new Date ()-beginTime) +" millisecond ") if (rcommentidwords undefined & & rcommentidmessages =") {$(" html,body ") .animate ({scrollTop: $(" # comment_item_ "+ rcommentid). Offset (). Top}, 1000);}); return false } you can clearly see that the last data submitted by POST data changed the name of the parameter, and several other parameters can be seen to be either empty or dead by looking at the js file, so don't worry about it. At the same time, it was found that the "comment_usrId" was also killed? Then just comment one variable and it's done.

Blog_url = "http://blog.csdn.net/u013291394/comment/submit?id=50444369"comment = {:" Water Army Review Test ",} R2 = session.post (blog_url, comment) print (r2.text) take a look at the effect:

Of course, the final parameter passing above can also be manually commented and crawled with the package crawling software, but it also provides a direction for my automated comments by looking at the commetn.js file. There is a load_comment_form () method that is used to load comment-form, which gives the definition of action:

Action= "/'+ username +'/ comment/submit?id=' + fileName +'" run the script to test the effect:

This is the end of the content of "how to automate the Water Army Review with Python". Thank you for your reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

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

Internet Technology

Wechat

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

12
Report