Last active
December 20, 2015 01:19
-
-
Save zzh8829/6047726 to your computer and use it in GitHub Desktop.
Baidu Tieba Signer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #! usr/bin/python3 | |
| import urllib.request as ur | |
| import urllib.parse as up | |
| import time,json,re | |
| cookie = "" | |
| class TiebaSigner: | |
| def __init__(self): | |
| self.opener = ur.build_opener() | |
| self.opener.addheaders = [('User-Agent','Mozilla/5.0 (Windows NT 6.1; WOW64; rv:21.0) Gecko/20100101 Firefox/21.0'), | |
| ('Connection','keep-alive'),('Referer','http://wapp.baidu.com/'),('Cookie',cookie)] | |
| if not json.loads(self.urlget('http://tieba.baidu.com/dc/common/tbs?t=123456'))['is_login']: | |
| print("Login Failed") | |
| exit() | |
| def sign(self,tbid): | |
| print("Sign Tieba: %s"%(up.parse_qs("a=%s"%tbid,encoding="gbk"))['a'][0]) | |
| url = "http://tieba.baidu.com/mo/m?kw="+tbid | |
| web = self.urlget(url) | |
| qd = re.findall('<td style="text-align:right;"><a href="(.*?)">签到</a>',web) | |
| if qd: | |
| link = qd[0].replace('&','&') | |
| res = self.urlget("http://tieba.baidu.com"+link) | |
| if "签到成功" in res: | |
| print("Sign done") | |
| else: | |
| time.sleep(1) | |
| res = self.urlget("http://tieba.baidu.com"+link) | |
| if "签到成功" in res: | |
| print("Sign Done") | |
| else: | |
| print("Sign Failed") | |
| elif re.findall('<span >已签到</span>',web): | |
| print("Already Signed") | |
| else: | |
| print("Unknow Error") | |
| def urlget(self,url): | |
| data = self.opener.open(url).read() | |
| try: | |
| return data.decode('u8') | |
| except: | |
| return data.decode('gbk') | |
| def tiebalist(self): | |
| url = "http://tieba.baidu.com/f/like/mylike?" | |
| web = self.urlget(url) | |
| page = 2 | |
| while True: | |
| nxt = self.urlget(url+"&pn="+str(page)) | |
| if '/f?kw' in nxt: | |
| web+=nxt | |
| page+=1 | |
| else: | |
| break | |
| return re.findall('/f\?kw=(.*?)"',web) | |
| def autosign(self): | |
| for name in self.tiebalist(): | |
| self.sign(name) | |
| if __name__== '__main__': | |
| tb = TiebaSigner() | |
| tb.autosign() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
厉害,下来研究一下!多谢!