Created
June 29, 2015 08:23
-
-
Save choleraehyq/60b7ecf9d413a2b20c1e to your computer and use it in GitHub Desktop.
贴吧自动签到的脚本
This file contains 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
from urllib import request, parse | |
from http import cookies, cookiejar | |
import re | |
import time | |
cookie = cookiejar.CookieJar() | |
opener = request.build_opener(request.HTTPCookieProcessor(cookie)) | |
def set_cookie(name, value): | |
cookie = cookiejar.Cookie( | |
version = 0, | |
name = name, | |
value = value, | |
domain = '.baidu.com', | |
path = '/', | |
expires = None, | |
discard = False, | |
port = None, | |
port_specified = False, | |
domain_specified = True, | |
path_specified = True, | |
domain_initial_dot = False, | |
comment = None, | |
comment_url = None, | |
rest = {}, | |
secure = False | |
) | |
return cookie | |
def find_title(content): | |
regexp = r'title="(.+?)">\1</a>' | |
regexp = re.compile(regexp) | |
return re.findall(regexp, content) | |
def get_all_like(): | |
like_url = "http://tieba.baidu.com/f/like/mylike?&pn=" | |
page = 1 | |
res = [] | |
while True: | |
cur_page = like_url + str(page) | |
print(cur_page) | |
content = opener.open(cur_page).read() | |
content = content.decode("gbk") | |
res += find_title(content) | |
if content.find("下一页") == -1: | |
break | |
page += 1 | |
return res | |
def sign(likelist): | |
post_url = "http://tieba.baidu.com/sign/add" | |
print(likelist) | |
for name in likelist: | |
form_data = { | |
"ie": "utf-8", | |
"kw": name, | |
"tbs": "245b72e6a5b41f6b1435484763" | |
} | |
try: | |
sign_res = opener.open(post_url, parse.urlencode(form_data).encode()) | |
except: | |
print(name, "签到失败") | |
finally: | |
time.sleep(30) | |
if __name__ == "__main__": | |
BDUSS = "VCRVdVN3FsSUtRbXpZZ0xPME8zeW1KZGZGVEM1ejBWR1JFUG5YVXhidkVTYmRWQVFBQUFBJCQAAAAAAAAAAAEAAAC5Wp4DUVExOTk3MDgxNAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMS8j1XEvI9VUl" | |
cookie.set_cookie(set_cookie("BDUSS", BDUSS)) | |
likelist = get_all_like() | |
sign(likelist) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment