百度贴吧,当你的贴吧很多的时候,一个一个去签很麻烦,写了一个python程序。去实现一次性签到。
import urllib.request
import re
import urllib.parse
import json
import ssl
import urllib.parse
ssl._create_default_https_context=ssl._create_unverified_context
headers={
"Cookie":"BAIDUID=42DBD619DA13335066A487D939D67E56:FG=1; TIEBA_USERTYPE=360a690f292cc12e991df59c; FP_UID=5d59c27f862842b5aedaa071ccff9679; BDUSS=mk4Y3YzT2JtVU5WUlJkenkyTkZRU2wwSzR4NWVleE5aSWlSeXdIVTJuQ2duQkpiQVFBQUFBJCQAAAAAAAAAAAEAAADq6sW5b2vQ6NKqtc219wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAKAP61qgD-taY; STOKEN=1e528b6cf8d14bf33aabf29fbc36212afac317e58f058d73301ff2336f6e8a3b; TIEBAUID=a4634cd49b93c9d90e1e065a; rpln_guide=1; Hm_lvt_98b9d8c2fd6608d564bf2ac2ae642948=1525354386,1525355470,1525405669; Hm_lpvt_98b9d8c2fd6608d564bf2ac2ae642948=1525405669"
"User-Agent""Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.139 Safari/537.36"
}
def SignAdd(kw,tbs_data):
url="https://tieba.baidu.com/sign//add"
post_data={
"ie":"utf-8",
"kw":kw,
"tbs":tbs_data,
}
data=urllib.parse.urlencode(post_data).encode("utf-8")
post_req=urllib.request.Request(url=url,data=data,headers=headers)
try:
return
(kw,json.loads(urllib.request.urlopen(post_req).read().decode("utf-8"))["data"]["errmsg"])
except:
return (kw,"faild")
forum_list = re.findall('"forum_id":(.*?),"forum_name":"(.*?)"', urllib.request.urlopen(urllib.request.Request(
url="http://tieba.baidu.com/index.html", headers=headers)).read().decode())
for eve_forum in forum_list:
kw=eve_forum[1].encode('latin-1').decode("unicode_escape")
forum_url = "http://teiba.baidu.com/f?kw=" + urllib.parse.quote(kw)
tbs_data= re.findall('\'tbs\':"(.*?)"',urllib.request.urlopen(urllib.request.Request(url=forum_url,headers=headers)).read().decode("utf-8"))[0]
print("-".join(SignAdd(kw,tbs_data)))