python-Weibo demo Landing

Source: Internet
Author: User
Tags base64

Weibo of the simulation landing is a comparison pit, see a lot of great God on the Internet post, and I saw the microblog of the log when the JSON data: 1, found in the login when entering the account with Chrome can see there will be a prelogin such as the URL, after the URL will have a large number of random numbers. I tested, found that in the absence of random numbers in the case of the URL can also get the required severtime, nonce, and so on several data. 2, through Chrome to view the JSON data can see the user name and password encryption, and then find the online great god information can get the user name Su, and password sp. Post the data again to get a redirected microblog landing site. 3, the site with regular expression extracted, and then with the cookie data can be landed. And then you can do whatever you want.

#_*_coding:utf-8 _*_ImportBase64ImportUrllibImportUrllib2ImportReImportRSAImportCookielibclassWeibo (object):def __init__(self, username, password): Self.user=Base64.b64encode (username) self.pwd=Password @propertydefget_pre_url_values (self): values_dict={} su=Self.user Pre_url='Https://login.sina.com.cn/sso/prelogin.php?entry=weibo&callback=sinaSSOController.preloginCallBack &su='                        + str (su[:-1]) +'%3d&rsakt=mod&checkpin=1&client=ssologin.js (v1.4.18)'Header= {            'user-agent':'mozilla/5.0 (Windows NT 6.3; WOW64) applewebkit/537.36 (khtml, like Gecko) chrome/35.0.1916.153 safari/537.36'} request= Urllib2. Request (Pre_url, headers=header) HTML= Urllib2.urlopen (Request). Read (). Decode ('Utf-8') P= Re.compile (r'"Servertime":(. *?),') values_dict['Servertime'] = P.search (HTML). Group (1). Strip ('\"') P1= Re.compile (r'"Pcid":(. *?),') values_dict['Pcid'] = P1.search (HTML). Group (1). Strip ('\"') P2= Re.compile (r'"Nonce":(. *?),') values_dict['nonce'] = P2.search (HTML). Group (1). Strip ('\"') P3= Re.compile (r'"PubKey":(. *?),') values_dict['PubKey'] = P3.search (HTML). Group (1). Strip ('\"') P4= Re.compile (r'"RSAKV":(. *?),') values_dict['rsakv'] = P4.search (HTML). Group (1). Strip ('\"')        returnvalues_dictdefGet_password (Self, blog_values):" "This function is a copy of the JSON data of Weibo and the great God method on the Web (copied) ^_^" "Rsapubkey= Int (blog_values['PubKey'], 16) Key= RSA. PublicKey (Rsapubkey, 65537) Massage= STR (blog_values['Servertime']) +'\ t'+ STR (blog_values['nonce']) +'\ n'+str (self.pwd) password=rsa.encrypt (massage, key) SP= Password.encode ('Hex')        returnSPdefLogin_weibo (self, blog_values, SP): Values= {            'entry':"Weibo",            'Gateway':'1',            ' from':"',            'SaveState':'7',            'Userticket':'1',            'Pagerefer':"",            'Cfrom':'1',            'VSNF':'1',            'su': Self.user,'Service':'Miniblog',            'Servertime': blog_values['Servertime'],            'nonce': blog_values['nonce'],            'Pwencode':'RSA2',            'rsakv': blog_values['rsakv'],            'SP': SP,'SR':"1440*900",            'encoding':'UTF-8',            'Prelt':'503',            'URL':'Http://weibo.com/ajaxlogin.php?framelogin=1&callback=parent.sinaSSOController.feedBackUrlCallBack ',            'ReturnType':'META'} header= {            'user-agent':'mozilla/5.0 (Windows NT 6.3; WOW64) applewebkit/537.36 (khtml, like Gecko) chrome/35.0.1916.153 safari/537.36'} URL='http://login.sina.com.cn/sso/login.php?client=ssologin.js (v1.4.18)'        " "Get cookie Information" "CJ=Cookielib. Cookiejar () Cj_support=Urllib2. Httpcookieprocessor (CJ) Opener=Urllib2.build_opener (cj_support) data=Urllib.urlencode (values)Try: Response= Urllib2. Request (URL, Headers=header, data=data) HTML= Opener.open (response). Read (). Decode ('GBK')        exceptException, E:PrintE.message P= Re.compile (r'location\.replace\ (\ ' (. *?) \ ' \)') URL= P.search (HTML). Group (1)        Try: Url_request=Urllib2. Request (URL) response_url=opener.open (url_request) page= Response_url.read (). Decode ('Utf-8') P2= Re.compile (r'" UserDomain": "(. *?)"') Dom= P2.search (page). Group (1) Login_url='http://weibo.com/'+Dom Request_login_url=Urllib2. Request (login_url) Response_login_url=Opener.open (request_login_url) per_html= Response_login_url.read (). Decode ('Utf-8')        exceptexception:per_html='Login Failed'        returnper_htmlif __name__=='__main__': Wbobj= Weibo ('User name','Password') SP=Wbobj.get_password (wbobj.get_pre_url_values) HTML= Wbobj.login_weibo (Blog_values=wbobj.get_pre_url_values, sp=sp)PrintHtml

, such as: Take the Goddess's photos all, automatically check the goddess's microblog and send you the mail, next time to do this. Recently the bad insomnia, quickly find a job!!

python-Weibo demo Landing

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.