Python's own proactive review of actual combat
Playing Csdn blog for one months, and gradually found some interesting things, often someone with the same comments everywhere brush. Do not know is to add no use of points, or purely to express the good man. Then the problem comes, this kind of boring thing is of course best to be self-motivated. I have to try a piece, 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 some other hidden parameters, such as LT, Excution, and so on, the good programmer also wrote the reason why can not be directly authenticated: Lack of serial number, then visit once to get the serial number, with BeautifulSoup to analyze the page content crawl serial number, At the same time, 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)
All right. Now can get my message information, indicating that has successfully solved the landing problem, then the initiative of the Navy comments should be in the immediate.
Comment on your own initiative
This is a good study. Find a random 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 result is returned {"result":0,"content":"评论内容没有填写!","callback":null,"data":null}
.
It's kind of interesting. Should be in the JS in the number of parameters to be processed.
Then pull the JS out to see. Web page to search the JS file, there is a comment.js. That's it. In the form above, you can see that the subform method was called when the commit was made, and see the methods such as the following:
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 comment is 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!
评论耗时:" + (new Date() - beginTime) + "毫秒") if (rcommentid!=undefined && rcommentid != "") { $("html,body").animate({ scrollTop: $("#comment_item_" + rcommentid).offset().top }, 1000); } } } }); return false;}
Can clearly see the last post submitted data changed the name of the data
parameter, there are several other parameters by looking at the JS file can see is not empty is dead, do not care about him.
At the same time, the discovery "comment_usrId"
is also to die? 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:
Self-initiated
Of course, the above finally the number of the pass can also be manually review and grab the package software to crawl, just by looking at commetn.js
the file also give my own proactive comments provide the direction, there is a load_comment_form()
way. is used to load comment-form, it gives the definition of action:
action="/‘ + username + ‘/comment/submit?id=‘ + fileName + ‘"
The writing was very clear. I just grab the page's author name and the number of the article to be able to enjoy the water review, casually choose a crawl article entrance, such as the latest blog entry
Ref=toolbar_logo ">http://blog.csdn.net/?
Ref=toolbar_logo, crawls the URL with BeautifulSoup and parses the username and filename in it to form the action and raise the comment.
Execute the script to try the effect:
Open Comment Management to see:
Self-motivated Comment success.
Written in the last
This article is written only to prove your own ideas, not to use and do not want to be used to maliciously brush comments .
- This article is original by Drfish (http://www.drfish.me/). Reprint please indicate the original link, thank you.
Please visit my GitHub (Https://github.com/gavinfish/Awesome-Python/tree/master/HotBlog) for the source code.
Python's own proactive review of actual combat