赞
踩
练练手,只需要将cookies改成自己的 便即可运行。
from bs4 import BeautifulSoup import requests import re ''' 携带cookies登入 ''' def TXsgin(): url = "https://film.qq.com/x/autovue/grade/?ptag=Vgrade.share&url_from=share&second_share=0&share_from=copy" # 浏览器登录后得到的cookie,也就是刚才复制的字符串 cookie_str = r'(这里改成浏览器登录后得到的cookie,去掉这里的括号)' # 把cookie字符串处理成字典,以便接下来使用 cookies = {} for line in cookie_str.split(';'): key, value = line.split('=', 1) cookies[key] = value print(cookies) headers = { 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.25 Safari/537.36 Core/1.70.3741.400 QQBrowser/10.5.3863.400', 'accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3', 'Referer': 'https://film.qq.com/x/autovue/grade/?ptag=Vgrade.share&url_from=share&second_share=0&share_from=copy', 'accept-encoding':'gzip, deflate,br', 'accept-language':'zh-CN,zh;q=0.9' } response = requests.get(url, headers=headers,cookies=cookies) #解决编码乱码问题 if response.status_code == 200: response.encoding = 'utf-8' print("响应编码:",response.encoding) soup=BeautifulSoup(response.text,'lxml') Vnum=soup.select('#page1 > div > div.main > div > section.mod_mession > div > div.detail_content > div > div.detail_top > div.left > div.num > span') getV=soup.select('#page1 > div > div.main > div > section.mod_mession > div > div.detail_content > div > div.detail_top > div.right > div.highlight') levels=soup.select('#page1 > div > header > div.user_info > div.top > div.calibrate > div.current_bright') needs=soup.select('#page1 > div > div.main > div > section.mod_mession > div > div.detail_content > div > div.detail_mid > div > div.title > span') for level in levels: levels_msg=level.get_text() # print("我的等级:",levels_msg.strip()) for v in Vnum: v_msg=v.get_text() # print("我的v力值:",v_msg) for getvs in getV: getV_msg=getvs.get_text() # print("本月已获得:",getV_msg) for need in needs: needs_msg=need.get_text() # print(needs_msg.strip()) msgAll="LV:"+levels_msg.strip()+" 我的v力值:"+v_msg+"本月已获得:"+getV_msg+needs_msg.strip() print(msgAll) return msgAll if __name__ == '__main__': TXsgin()
最后可以关注一下我个人微信公众号,不定期更新一些好用的资源以及生活上的点点滴滴~~
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。