当前位置:   article > 正文

python爬取腾讯视频会员V力值_python爬取腾讯vip电视剧

python爬取腾讯vip电视剧

python爬取腾讯视频会员V力值

练练手,只需要将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()
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51

最后可以关注一下我个人微信公众号,不定期更新一些好用的资源以及生活上的点点滴滴~~
在这里插入图片描述

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Monodyee/article/detail/156393?site
推荐阅读
相关标签
  

闽ICP备14008679号