首页 > 代码库 > 【Python】微博自动抢红包

【Python】微博自动抢红包

 

# -*- coding: utf-8 -*-import requestsimport js2xmlfrom lxml import etreeheaders = {# 这边cookie替换成你的cookie‘Cookie‘:‘9b‘,‘User-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‘,}# 获取红包列表def getuid():    url = ‘http://chunjie.hongbao.weibo.com/hongbao2017/h5index‘    # 带上request headers    z = requests.get(url, headers=headers)    #print(z.status_code)    if z.status_code == 200:       # 这边是查找所有的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://hongbao.weibo.com/h5/aboutyou?groupid=1000110‘    # 带上request headers    z = requests.get(url, headers=headers)    #print(z.status_code)    if z.status_code == 200:       # 这边是查找所有的ouid       name=etree.HTML(z.content).xpath(‘//span[@class="nickname"]‘)       print(name[0].text)    return name# 获取st的值def getst(url):    # 带上request headers    z = requests.get(url, headers=headers)    # 获取第一段JavaScript,并去掉 <!--拆包页-->,防止中文报错    jscode = etree.HTML(z.content).xpath(        "//script[contains(., ‘weibo‘)]/text()")[0].replace(u‘<!--拆包页-->‘, ‘‘)    # 使用js2xml 把JavaScript代码替换成xml    parsed_js = js2xml.parse(jscode)    # 打印下 xml    # print js2xml.pretty_print(parsed_js)    # 从上面可以看到st在哪,然后用xpath写出来    st = parsed_js.xpath(‘//property[@name="st"]/string/text()‘)[0]    return st# 抢红包def tj(url, uid, st, tjheaders):    # 生成需要发送的data    data = http://www.mamicode.com/{>

  

【Python】微博自动抢红包