Post-registration assistant based on python3+requests

Source: Internet
Author: User
Tags code tag

Because always forget to sign in, so try to write a check-in script, because the use of Python3, so can not use URLLIB2, so chose requests, it turns out, requests than Urllib2 good. The overall idea is relatively simple, is to simulate the process of Baidu Landing Interactive, and then to obtain cookies and save, and then use cookies to log in, and then simulate the client's transceiver process to interact, but in fact encountered a lot of problems, here to record the debugging experience

The main program is relatively simple, that is, to determine whether the landing is successful, and then start checking in, which determines whether the landing is successful, the reference program is to access the address "http://tieba.baidu.com/i/i/forum?&pn=1", detection status value, Using the browser to capture the package is returned 302 automatic jump, but even if the program added Allow_redirects=false, the return value is 200, so the author instead of stick to the home page https://tieba.baidu.com/index.html, and then detect if there is a keyword "Love stroll"

To get the bar list, most of the programs use "http://tieba.baidu.com/f/like/mylike?&pn=" to get the bar list, and then the page, but I found in the test that this URL does not have a corresponding list, And sometimes there's no data when you open it directly on a Web page, so flip through a lot of code on GitHub and finally find the address "http://tieba.baidu.com/mo/m?tn=bdFBW&tab=favorite". It is unclear how many bars can be accommodated per page (the number of tests is 120), if there is a problem can be feedback to the author

Check-in is to get the FID value and TBS value of post, the first two values can be accessed in the web version of the corresponding bar to get (in fact, it can be customized, this parameter is not required, in order to reduce the risk, or choose as far as possible correct, complete post information), according to the return value inside the Error_ Code can get the check-in situation, in order to prevent the sign-in to the post registration information, before checking in to add a test, is to access the Web page corresponding to the bar, and then find the corresponding keywords, here with the self-brought regular expression library re, If you are familiar with BeautifulSoup can use this library to implement, and continuous access speed can not be too fast, otherwise it will return error code (Web page check-in will bounce verification code, the client has no verification code, temporarily do not know if there will be other problems, in order to secure and stable, check-in between the different bar added a random delay)

Analog client Check-in post information needs to be encrypted once (Web version does not need), this is a direct migration of the reference Code, the author did not personally grasp the package test, so do not explain

The above is a visit with a cookie, the most important of which is Bduss, this is the Baidu landing when the successful return of the cookie (also will return Stoken, Ptoken and other cookies, but not required), or even only this one cookie can be accessed Baidu, So after the completion of the mock check-in and try to write the account of the simulation login Baidu, because the acquisition of Bduss experience is not convenient

Login Baidu This code is the card for the longest time, because ... A lot of opinions, too many attempts

Landing needs to visit Baidu first page, and then access to the login interface, access to the two cookies (only access to the login interface is also possible), because the normal use of Web pages when landing is step by step in, and can not be directly post information, So it is illegal to post in 1 cases of cookies that do not have the top two pages (to get a cookie, like a baiduid), Then take the cookie to visit Baidu's API page to get token (no access to the previous page of the cookies obtained by the fisrt-should be string type:0,1! means the lack of information), After obtaining the post with the account and token token (here the headers is special, see the code, with the normal headers can not log in), and then based on the return value of the error to determine whether there is a verification code (basic), and then download the verification put into a GIF file and open, Manually enter the verification code and then take the verification code tag and the contents of the verification code and then post, and then according to the return value of the situation (note do not lose the wrong password, multiple errors will be locked for 3 hours!) If the login succeeds in saving the cookies, the next time you need to log in with cookies, and will refresh and automatically save the new cookies after each login, it is unclear how long it will expire and need to observe

In the process of simulating the post, we found that the post information of the grab packet was much more than the reference code, so we looked up the relevant data, then referred to the article "https://www.cnblogs.com/qiyeboy/p/5722424.html". Wrote a long tedious code, and finally found that these parameters are not required ... Just a practiced hand.

This paper records some problems encountered in the development process and experience, code hosting on Git "Https://github.com/Pyrokine/tieba_autosign", Create an empty file of a cookie in the folder (without writing the corresponding creation code)

Thanks for the following geeks

Https://github.com/chaonet/baidu_tieba_auto_sign

http://blog.csdn.net/programmer_sir/article/details/38961109

Post-registration assistant based on python3+requests

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.