承接国内外服务器租用托管、定制开发、网站代运营、网站seo优化托管接单、网站代更新,新老站点皆可!!咨询QQ:3787320601
当前位置:首页  >  软件开发  >  python 爬腾讯视频

python 爬腾讯视频

管理员 2023-08-24 08:13:27 软件开发 0 ℃ 0 评论 1592字 收藏

python 爬腾讯视频

随着网络时期的到来,各种网络媒体如雨后春笋般地出现,各类视频平台也层见叠出,而腾讯视频便是其中很是知名的一家。本文将介绍怎样使用Python爬取腾讯视频的信息。

#导入必要的库
import requests
from lxml import etree
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3'
}
# 获得所有视频
def get_all_videos():
url = 'https://v.qq.com/'
response = requests.get(url, headers=headers)
html = etree.HTML(response.text)
# 获得所有视频的 url 
videos_urls = html.xpath('//div[@class="mod_title"]/a/@href')
# 获得所有视频的标题 
videos_title = html.xpath('//div[@class="mod_title"]/a/text()')
for url, title in zip(videos_urls, videos_title):
print(url, title)
# 获得指定视频的信息
def get_video_info(video_url):
response = requests.get(video_url, headers=headers)
html = etree.HTML(response.text)
# 获得视频名称 
video_title = html.xpath('//h1[@class="player_title"]/text()')[0]
# 获得视频时长 
video_duration = html.xpath('//span[@class="duration"]/text()')[0]
# 获得视频发布时间 
video_pubtime = html.xpath('//span[@class="pub"]/text()')[0]
print(video_title, video_duration, video_pubtime)
if __name__ == '__main__':
get_all_videos()
get_video_info('https://v.qq.com/x/cover/2xrh1eoyttpb034.html')

以上便是使用Python爬取腾讯视频的方法,通过网络要求和XPath解析,我们可以获得到各视频的详细信息。希望对您有所帮助!

文章来源:丸子建站

文章标题:python 爬腾讯视频

https://www.wanzijz.com/view/73900.html

上一篇:python 的默许值

下一篇:python 爬美剧

TAG: php教程 centos

相关文章

Related articles

X

截屏,微信识别二维码

微信号:weimawl

(点击微信号复制,添加好友)

打开微信