"Python" Weibo automatically steals red envelopes

Source: Internet
Author: User

#-*-Coding:utf-8-*-import requestsimport js2xmlfrom lxml Import etreeheaders = {# This cookie is replaced with your cookie ' cookie ': ' 9b ', ' Us Er-agent ': ' mozilla/5.0 (Linux; Android 4.0.4; Galaxy Nexus build/imm76b) applewebkit/535.19 (khtml, like Gecko) chrome/18.0.1025.133 Mobile safari/535.19 ',}# Get red Envelopes List def getuid (): url = ' Http://chunjie.hongbao.weibo.com/hongbao2017/h5index ' # with request headers Z = Requests . Get (URL, headers=headers) #print (z.status_code) if Z.status_code = = 200: # This side is looking for all ouid Alluid = etree . HTML (z.content). XPath ('//div[@class = ' M-auto-box ']/@action-data ') #print (alluid) #print (etree. HTML (z.content). XPath ('/html/body/div[1]/section/div[2]/span ')) return alluiddef getname (URL): #url = ' Http://hongba o.weibo.com/h5/aboutyou?groupid=1000110 ' # with request headers z = requests.get (URL, headers=headers) #print (z.stat Us_code) If Z.status_code = = 200: # This side is looking for all the Ouid name=etree. HTML (z.content). XPath ('//span[@class = ' nickname ']') print (name[0].text) return name# get St's value def getst (URL): # with request headers z = requests.get (URL, headers =headers) # Get the first piece of JavaScript and remove the <!--unpacking page--&GT, prevent Chinese error jscode = etree. HTML (z.content). XPath ("//script[contains (., ' Weibo ')]/text ()") [0].replace (U ' <!--unpacking page--', ') # Use Js2xml to JavaScript code replaced with XML PARSED_JS = Js2xml.parse (jscode) # Print under XML # print Js2xml.pretty_print (PARSED_JS) # from above you can see Where is St, then write it with XPath st = Parsed_js.xpath ('//property[@name = "St"]/string/text () ') [0] return st# Rob Red envelopes def TJ (URL, uid, St, tjheaders): # Generates data data that needs to be sent = {' GroupID ': ' 1000110 ', ' uid ': uid, ' share ': ' 1 ', ' st ': st} # here     Post,headers added Referer z = requests.post (URL, data=data, headers=tjheaders) #print (Z.json ()) # to show the resulting results in JSON form _ = Z.json () # If there is "OK" in JSON, the submission is successful, otherwise the error message is returned #print (_[' OK ') #if _[' OK ']!=1: #print (_) Print (_[' da Ta ' [' Result '] [' name ']) # Else: #print (_[' Error_code ')) If __name__ = = ' __main__ ': # get all uid UIDs = Getuid () # Get St #print (st) url = ' Http://hongbao.weibo.com/h5/abou        tyou?groupid=1000110 ' getname (url) st = getst (URL) for UID in UIDs: #print (UID) # URL to generate a red envelope page url = ' http://hongbao.weibo.com/h5/aboutyou?groupid=1000110&ouid=%s '%uid # generates a URL to click on the "Grab Red Envelopes" page Tju RL = ' http://hongbao.weibo.com/aj_h5/lottery?uid=%s&groupid=1000110&wm= '%uid getname (URL) # add refer Er, if not add will error headers[' Referer ' = URL tjheaders = headers try: # Click "Grab Red Envelopes" TJ (Tjurl,ui D,st,tjheaders) Except:pass

  

"Python" Weibo automatically steals red envelopes

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.