Python吧,python百度贴吧发帖签到_python 爬虫 百度贴吧签到小工具

 2023-09-23 阅读 26 评论 0

摘要:import requests,re,timePython吧。header ={"Cookie":"登陆过账号后的cookie 必须填写",爬虫技术python,"User-Agent":"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36&

import requests,re,time

Python吧。header ={

"Cookie":"登陆过账号后的cookie 必须填写",

爬虫技术python,"User-Agent":"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36"

}

#访问个人帐号下的贴吧主页

url = "百度首页--右上角贴吧--右上角用户名(我的贴吧) 然后把url填到这里"

html = requests.get(url,headers=header)

#print(html.text)

#提取贴吧相关的ID 名称等信息

s1 = r'"forum_id":(.*?),"forum_name":"(.*?)"'

tieba_info = re.compile(s1,re.S).findall(str(html.text))

#print(tieba_info)

for i in tieba_info:

time.sleep(3)#访问CD要控制好,否则容易出现验证码,导致签到失败

print(i[1])

print(i[1].encode("latin-1"))

#获取可以签到的全部贴吧名字

#print(i[1].encode("latin-1").decode("unicode_escape"))

#获取tbs 发送签到请求需要获得名为tbs的数据 他在页面信息里面

tieba_name = (i[1].encode("latin-1").decode("unicode_escape"))

tieba_link = "https://tieba.baidu.com/f?kw=" + tieba_name

info = requests.get(tieba_link,headers=header)

#print(info.text)

s2 =r"tbs': \"(.*?)\"" #单双引号都有 注意转义字符

tieba_tbs = re.compile(s2,re.S).findall(str(info.text))[0]

#print(tieba_tbs)

#签到的postdata

qiandao_url = "https://tieba.baidu.com/sign/add"

qiandao_data = {"ie":"utf-8",

"kw":tieba_name,

"tbs":tieba_tbs} #tbs这个数据意义不明 可以在附近相关网页代码中搜索看看 是否能发现关联

#实现签到 是否成功 可以看返回信息

try:

qiandao = requests.post(qiandao_url,data=qiandao_data,headers=header)

#print(qiandao.text)

print(tieba_name,"签到")

except:

print(tieba_name,"异常")

continue

版权声明:本站所有资料均为网友推荐收集整理而来,仅供学习和研究交流使用。

原文链接:https://hbdhgg.com/5/90868.html

发表评论:

本站为非赢利网站,部分文章来源或改编自互联网及其他公众平台,主要目的在于分享信息,版权归原作者所有,内容仅供读者参考,如有侵权请联系我们删除!

Copyright © 2022 匯編語言學習筆記 Inc. 保留所有权利。

底部版权信息