Python Demo login Open source China

Source: Internet
Author: User
Tags urlencode

My personal blog (Fat Dragon's blog) has published a new article!
Welcome to come to read, the following is the connection address of the article

http://www.comingcode.com/?p=371


following the previous article simulation login Baidu Space (http://www.comingcode.com/?p=357), in order to promote their own blog, through the Internet to search for data and analysis of HTTP packets, I again use Python simulation of open-source China's login operations, Being able to post a blog can also send a move.

the specific implementation process is also the same as the login Baidu space, are required to analyze the content of HTTP sent packets.

through the simulation login process of these two articles, when parsing http, As a result of the previous company analysis 802.1x communication steps using Wireshark to grab the package, all the first directly using this tool to grab Packet Analysis HTTP package, this tool is very powerful, but not suitable for novice use, to later on the internet to see everyone is recommended to use the Fiddler to analyze the tool, the middle toss not Less time, but also a learning to new tools, but also a progress it.


PS: Finally I ran this code on my own VPS, found incredibly synchronized with the previous several blog posts to Oschina can, the back is not, but if the use of this machine to test, it has been possible, is the OSC for foreign IP has special treatment?

the implementation code for the related class is posted below:

    

#-*-Coding:utf8-*-' @author: Dragon ' import urllib2import urllibimport cookielibimport hashlibimport reclass OSC: def __init__ (self): Self.usercode = "" Self.userid = "" SELF.CJ = Cookielib.        Lwpcookiejar (); Self.opener = Urllib2.build_opener (urllib2.        Httpcookieprocessor (SELF.CJ));    Urllib2.install_opener (Self.opener);                        #登录 def login (self, name, pwd): Loginpostdata = {' Email ': name,        ' pwd ': HASHLIB.SHA1 (pwd). Hexdigest () #密码SHA1加密}; #必须设置head否则返回403拒绝 loginrequest = urllib2.        Request (' Https://www.oschina.net/action/user/hash_login ', Urllib.urlencode (Loginpostdata));        Loginrequest.add_header (' Accept ', ' */* ');        Loginrequest.add_header (' accept-language ', ' zh-cn,zh;q=0.8 '); Loginrequest.add_header (' user-agent ', ' mozilla/5.0 (Windows NT 6.1;        WOW64) applewebkit/537.36 (khtml, like Gecko) chrome/28.0.1500.72 safari/537.36 '); Loginrequest.Add_header (' Content-type ', ' application/x-www-form-urlencoded ');        Sendpost = Urllib2.urlopen (loginrequest); #获取页面中的user_code和 user #user_code应该是账号加密后的结果 reqrequest = urllib2.        Request (' http://www.oschina.net/');        Reqrequest.add_header (' Accept ', ' */* ');        Reqrequest.add_header (' accept-language ', ' zh-cn,zh;q=0.8 '); Reqrequest.add_header (' user-agent ', ' mozilla/5.0 (Windows NT 6.1;        WOW64) applewebkit/537.36 (khtml, like Gecko) chrome/28.0.1500.72 safari/537.36 ');        Reqrequest.add_header (' Content-type ', ' application/x-www-form-urlencoded ');        Content = Urllib2.urlopen (reqrequest). read (); #用正则读取usercode和userid matchval = re.search (U ' name=\ ' user_code\ ' value=\ ' (? P<user_code>.*?)        \ '/> ', content);        Self.usercode = Matchval.group (' User_code '); Matchval = Re.search (U ' name=\ ' user\ ' value=\ ' (? P<user_id>.*?)        \ '/> ', content);    Self.userid = Matchval.group (' user_id '); #发动弹 def sendpopmsg (self, msg):        #终于可以发动弹了 dtpostdata = {' User_code ': self.usercode, ' user ': Self.userid,        ' msg ': Msg.encode ("UTF8")}; Dtrequest = Urllib2.        Request (' Http://www.oschina.net/action/tweet/pub ', Urllib.urlencode (Dtpostdata));        Dtrequest.add_header (' Accept ', ' */* ');        Dtrequest.add_header (' accept-language ', ' zh-cn,zh;q=0.8 '); Dtrequest.add_header (' user-agent ', ' mozilla/5.0 (Windows NT 6.1;        WOW64) applewebkit/537.36 (khtml, like Gecko) chrome/28.0.1500.72 safari/537.36 ');        Dtrequest.add_header (' Content-type ', ' application/x-www-form-urlencoded ');    Sendpost = Urllib2.urlopen (dtrequest);                     #发送博文 def sendblog (self, title, content, isprivate): PostData = {' User_code ': Self.usercode,                    ' Draft ': 176444, ' title ': Title.encode ("UTF8"), ' Catalog ': 407791,  ' Abstracts ': ', ' content ': Content.encode ("UTF8"),                  ' Content_Type ': 2, ' classification ': 430381, ' type ': 1,                    ' Privacy ': isprivate, ' deny_comment ': 0, ' auto_content ': 1, ' As_top ': 0} loginrequest = urllib2.        Request (' Https://www.oschina.net/action/blog/save ', Urllib.urlencode (postdata));        Loginrequest.add_header (' Accept ', ' */* ');        Loginrequest.add_header (' accept-language ', ' zh-cn,zh;q=0.8 '); Loginrequest.add_header (' user-agent ', ' mozilla/5.0 (Windows NT 6.1;        WOW64) applewebkit/537.36 (khtml, like Gecko) chrome/28.0.1500.72 safari/537.36 ');        Loginrequest.add_header (' Content-type ', ' application/x-www-form-urlencoded '); Sendpost = Urllib2.urlopen (loginrequest); if __name__ = = "__main__": Test = OSC () test.login (' [email protected] ' , ' pwd ') test. Sendpopmsg ("Move")



Python Demo login Open source China

Related Article

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.