吾爱破解 - LCG - LSG |安卓破解|病毒分析|www.52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 6851|回复: 44
上一主题 下一主题
收起左侧

[学习记录] python爬虫爬取腾讯视频

  [复制链接]
跳转到指定楼层
楼主
l2430478 发表于 2022-1-1 11:36 回帖奖励
本帖最后由 l2430478 于 2022-1-1 11:45 编辑

代码如下
[Python] 纯文本查看 复制代码
import requests
from lxml import etree
from selenium import webdriver
from fake_useragent import UserAgent

class tencent_movie(object):
    def __init__(self):
        ua = UserAgent(verify_ssl=False)
        for i in range(1, 100):
            self.headers = {
                'User-Agent': ua.random
                }
    def get_html(self,url):
        response=requests.get(url,headers=self.headers)
        html=response.content.decode('utf-8')
        return html
    def parse_html_tengxun(self,html):
        target=etree.HTML(html)
        links = target.xpath('//h2[@class="result_title"]/a/@href')
        host=links[0]
        res = requests.get(host, headers=self.headers)
        con = res.content.decode('utf-8')
        new_html = etree.HTML(con)
        first_select = int(input('1.电视剧\n2.电影\n'))
        if (first_select == 1):
            titles=new_html.xpath('//div[@class="mod_episode"]/span/a/span/text()')
            new_links=new_html.xpath('//div[@class="mod_episode"]/span/a/@href')
            for title in titles:
                print('第%s集'%title)
            select = int(input('你要看第几集:(输入数字即可)'))
            new_link = new_links[select - 1]
            last_host = 'https://api.akmov.net/?url=' + new_link
        else:
            last_host = 'https://api.akmov.net/?url=' + host
        self.driver = webdriver.Chrome()
        self.driver.maximize_window()
        self.driver.get(last_host)
    def main(self):
        name = str(input('请输入电视剧或电影名:'))
        url = 'https://v.qq.com/x/search/?q={}&stag=0&smartbox_ab='.format(name)
        html = self.get_html(url)
        self.parse_html_tengxun(html)

if __name__ == '__main__':
    spider=tencent_movie()
    spider.main()




免费评分

参与人数 10吾爱币 +11 热心值 +10 收起 理由
古韵新风 + 1 + 1 谢谢@Thanks!
wasdzzleyong + 1 用心讨论,共获提升!
yjn866y + 1 + 1 热心回复!
Lucifer_BW + 1 + 1 热心回复!
18259118093 + 1 + 1 我很赞同!
朝太阳奔跑 + 1 + 1 用心讨论,共获提升!
eetoo + 1 谢谢@Thanks!
xinyangtuina + 1 + 1 谢谢@Thanks!
ffly8 + 1 热心回复!
苏紫方璇 + 5 + 1 欢迎分析讨论交流,吾爱破解论坛有你更精彩!

查看全部评分

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

沙发
拣尽寒枝不肯栖 发表于 2022-1-1 11:38
本帖最后由 拣尽寒枝不肯栖 于 2022-1-1 11:59 编辑

马上去试试,谢谢
3#
galaxy1127 发表于 2022-1-1 12:27
4#
LaLaLand 发表于 2022-1-1 12:36
5#
TokeyJs 发表于 2022-1-1 12:36
这是搜索视频然后跳转到网页播放??
6#
 楼主| l2430478 发表于 2022-1-1 12:50 |楼主
TokeyJs 发表于 2022-1-1 12:36
这是搜索视频然后跳转到网页播放??

你这里不行吗?我这里可以啊。
7#
HelloWang 发表于 2022-1-1 14:41
一直报错。
8#
江苏男孩 发表于 2022-1-1 17:05
我也想学习爬图,感谢分享!
9#
ccb0429 发表于 2022-1-1 17:28
https://chromedriver.storage.googleapis.com/index.html   报错的可能是没有环境   或者没有安装谷歌浏览器   去这个网页里下载对应版本就欧克了   楼主用的selenium  需要用这个
10#
chuanshuo2017 发表于 2022-1-1 18:38
谢谢分享,学习了。
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则 警告:本版块禁止回复与主题无关非技术内容,违者重罚!

快速回复 收藏帖子 返回列表 搜索

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2024-5-11 08:41

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表