• 【Python】微博自动抢红包


    # -*- coding: utf-8 -*-
    import requests
    import js2xml
    from lxml import etree
    headers = {
    # 这边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 alluid
    
    def 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 = {
        'groupid': '1000110',
        'uid': uid,
        'share': '1',
        'st': st
        }
        # 这里使用了post,headers增加了Referer
        z = requests.post(url, data=data, headers=tjheaders)
        #print(z.json())
        # 把得到的结果以json形式展示
        _ = z.json()
        # 如果json中有“ok”,表示提交成功了,否则返回报错信息
        #print(_['ok'])
        #if _['ok']!=1:
            #print(_)
        print (_['data']['result']['name'])
       # else:
            #print (_['error_code'])
    if __name__ == '__main__':
        # 得到所有的uid
        uids = getuid()
        # 获取st
        #print(st)
        url = 'http://hongbao.weibo.com/h5/aboutyou?groupid=1000110'
        getname(url)
        st = getst(url)
        for uid in uids:
            #print(uid)
            # 生成红包页面的url
            url = 'http://hongbao.weibo.com/h5/aboutyou?groupid=1000110&ouid=%s' %uid
            
            # 生成点击“抢红包”页面的url
            tjurl = 'http://hongbao.weibo.com/aj_h5/lottery?uid=%s&groupid=1000110&wm=' %uid
            getname(url)
            # 添加Referer,如果不添加会报错
            headers['Referer'] = url
            tjheaders = headers
            try:
            # 点击“抢红包”
                tj(tjurl,uid,st,tjheaders)
            except:
                pass
    

      

  • 相关阅读:
    Salesforce PDF报价单制作
    salesforce 按钮(js) 点击调用后台类(触发批准流)
    salesforce接收站点传过来的json,解析并序列化json,在保存到salesforce的个案以及测试类
    salesforce 简单的PDF报价单打印
    零配件入库 Trigger 插入触发台账和零配件更新
    salesforce客户信息打印
    诺基亚携手魔声发布Purity Pro无线立体声耳机
    DSP/BIOS用户手册与驱动开发阅读笔记1
    混响基础知识(转载百度百科)
    第3季DSP read list
  • 原文地址:https://www.cnblogs.com/zeze/p/6985413.html
Copyright © 2020-2023  润新知