Python crawler Baidu Bar Registration widget

Source: Internet
Author: User

Import Requests,re,time
Header ={
"Cookie": "Cookie must be filled in after login",
"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 = "Baidu homepage-top right corner bar--Right top corner user name (my bar) and then fill in the URL here"
html = requests.get (Url,headers=header)
#print (Html.text)

Information such as #提取贴吧相关的ID name
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要控制好, otherwise easy to appear verification code, resulting in failure to sign in
Print (i[1])
Print (I[1].encode ("latin-1"))
#获取可以签到的全部贴吧名字
#print (I[1].encode ("latin-1"). Decode ("Unicode_escape"))

#获取tbs send a check-in request to get the data named TBS he is in the page information
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 ': \" (. *?) \ "" #单双引号都有 note the escape character
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这个数据意义不明 can search the relevant page code in the vicinity to see if the association can be found

#实现签到 whether the success can be seen return information
Try
Qiandao = Requests.post (Qiandao_url,data=qiandao_data,headers=header)
#print (Qiandao.text)
Print (Tieba_name, "sign in")

Except
Print (Tieba_name, "exception")
Continue

Python crawler Baidu Bar Registration widget

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.