百度贴吧签到脚本

无意中访问了wap版贴吧,然后搞了个贴吧签到,挂在VPS上,虽然不经常玩贴吧,有等级还是能满足小小的虚荣心的,废话不多说,直接上代码
首先需要先安装gevent和requests:
pip install requests
pip install gevent

import requests,time,gevent,gevent.monkey,re
from threading import Thread
gevent.monkey.patch_socket()

url="WAP版贴吧地址"
ba_cookie="贴吧cookie"
ba_name_tuple=('steam','python','golang','Erlang','汉服')#贴吧名称

headers={
'Accept':'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8',
'Accept-Encoding':'gzip, deflate',
'Accept-Language':'zh-CN,zh;q=0.8',
'Cookie':ba_cookie,
'Host':'tieba.baidu.com',
'Proxy-Connection':'keep-alive',
'Upgrade-Insecure-Requests':'1',
'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Safari/537.36'
}
#建立回话,TCP/IP底层重用,提高效率
s=requests.Session()
def run(ba_url,ba_name):
    qian_url=ba_url+ba_name
    s.get(qian_url,headers=headers)
def go():
    taske=[gevent.spawn(run,url,i) for i in ba_name_tuple]
    gevent.joinall(taske)
rebuild=re.compile(r"已签到")
def check(ba_name):
    content=s.get(url+ba_name,headers=headers).text
    return_list=rebuild.findall(content)
    if str(return_list)=="['已签到']":
        pass
    else:
        print (ba_name+"-->未签到/签到失败")
def checkgo():
    for g in ba_name_tuple:
        m=Thread(target=check,args=(g,))
        m.start()
if __name__=="__main__":
    index=input("how work?\n")
    if index=="go":
        star=time.time()
        go()
        print (time.time()-star)
    else:
        checkgo()

因为用了gevent和多线程,速度还是很恐怖的,实测1000个贴吧用时在6秒内,估计是目前最快的百度贴吧签到

你可能感兴趣的:(百度贴吧签到脚本)