The commentary on Python combat Navy

Source: Internet
Author: User

The commentary on Python combat Navy

Play Csdn Blog One months, and gradually found some interesting things, often someone with the same comment everywhere brush, do not know is to add no use of points, or purely to express the good man. So the question comes, this kind of boring thing is of course the best to be able to automate, oneself also to try a, purely entertainment.

Landing

To comment, of course, to be able to log in first, using the requests library for processing, try to see your own message list:

msg_url ="http://msg.csdn.net/"r = requests.get(msg_url, auth=(‘drfish‘‘password‘))

The result jumps to the landing screen, OK then look at the landing interface is how to login, find the form:

Found there are some hidden parameters, such as LT, Excution, and so on, good-hearted program Ape also write the reason why can not be directly certified: Lack of serial number, it is more visited once to get the serial number, with BeautifulSoup to analyze the page content crawl serial number, Also, because you want to operate across different domains, the session is introduced:

Msg_url ="http://msg.csdn.net/"Login_url ="https://passport.csdn.net/"headers = {' User-agent ':' 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 = {"username":"Drfish","Password":"Password","LT": Page.select ("[Name=lt]")[0]["Value"],"Execution": Page.select ("[Name=execution]")[0]["Value"],"_eventid":"Submit",}r = Session.post (Login_url, authentication) r2 = Session.get (msg_url) print (R2.text)

OK, now you can get my message, stating that the landing problem has been successfully solved, then the automated Navy review should be in the immediate.

Automatic comment

This is a good learning, casually find an article directly check the comment box form:

Submit a comment based on the above login code:

"http://blog.csdn.net/u013291394/comment/submit?id=50444369"comment = {    "comment_content""水军评论测试",    "comment_usrId":"531203"}r2 = session.post(blog_url, comment)print(r2.text)

The results are returned {"result":0,"content":"评论内容没有填写!","callback":null,"data":null} as such. A bit of meaning, it should be in JS in the parameters are processed. Then the JS pulled out to see, the Web search for JS file, there is a comment.js, it is. In the form above, you can see that the subform method was called at commit, and the method is as follows:

 function Subform(e) {    if(c_doing)return false;varContent = $.trim ($ (Editorid). Val ());if(Content = ="") {Commenttip ("The comment is not filled in!");return false; }Else if(Content.length > +) {Commenttip ("The comments are too long to be more than 1000 characters!" ");return false; }varCommentid = $ ("#commentId"). Val (); Commenttip ("commenting ...");varBeginTime =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": Commentid,"Content": Content,"Replyid": $("#comment_replyId"). Val (),"Boleattohome": $("#boleattohome"). Val ()}, Success: function (data) {C_doing =false; Commenttip (data.content);if(Data.result) {varrcommentid=$ ("#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 ("The success of the publication! Comment Time-consuming: "+ (New Date()-BeginTime) +"milliseconds")if(rcommentid!=undefined&& Rcommentid! ="")                {                    $("Html,body"). Animate ({scrolltop: $ ("#comment_item_"+ Rcommentid). Offset (). Top}, +); }            }        }    });return false;}

Can clearly see the last Post submitted data data changed the name of the parameter, there are several other parameters by looking at the JS file can see is not empty is dead, do not care about him. And also found on the "comment_usrId" dead? Then just comment a variable to get it done.

"http://blog.csdn.net/u013291394/comment/submit?id=50444369"comment = {    "content""水军评论测试",}r2 = session.post(blog_url, comment)print(r2.text)

Look at the effect:

Automation

Of course, the above final parameter pass can also be manually reviewed and grabbed by the package software, but by viewing the commetn.js file also gives me the direction of automated comments, there load_comment_form() is a way to load comment-form, it gives the definition of action:

action="/‘ + username + ‘/comment/submit?id=‘ + fileName + ‘"

Write very clear, I just grab the page's author name and article number can enjoy the water review, casually choose a crawl article entrance, such as the latest blog entry Http://blog.csdn.net/?ref=toolbar_logo, Use BeautifulSoup to crawl the URL and parse the username and filename into it to form the action and raise the comment.

Run the script and try the effect:

Open Comment Management to see:

Automated review success.

Written in the last

Writing this article is just to prove your idea, not to use it and not want someone to use it for malicious comment .

    • This article by Drfish (http://www.drfish.me/) Original, reproduced please indicate the original link, thank you.

Need reference source please visit my GitHub (https://github.com/gavinfish/Awesome-Python/tree/master/HotBlog).

The commentary on Python combat Navy

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.