梨视频网站视频下载

# 抓取梨视频网站的短视频
from lxml import etree
import os
import requests
import re
dirName="./videoLibs"
if not os.path.exists(dirName):
    os.mkdir(dirName)
url="https://www.pearvideo.com/category_59"
headers = {
    'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.132 Safari/537.36',
}
# session=requests.Session()
response_text=requests.get(url,headers=headers).text
tree=etree.HTML(response_text)
li_list=tree.xpath('//*[@id="listvideoListUl"]/li')
for li in li_list:
    video_href="https://www.pearvideo.com/"+li.xpath('./div/a/@href')[0]
    video_title=li.xpath('./div/a/div[2]/text()')[0]
#     print(video_href,video_title)
    video_detail_page=requests.get(video_href,headers=headers).text #每一个视频详情页源码
    regex='srcUrl="(.*?)",vdoUrl'
    video_url=re.findall(regex,video_detail_page,re.S)[0] #获得每一个视频的源地址
    video_path=dirName+"/"+video_title+".mp4"
    video_content=requests.get(video_url,headers=headers).content
    with open(video_path,"wb") as fp:
        fp.write(video_content)
    print(video_title,"下载完毕...")

 

posted @ 2020-05-08 00:06  佛祖让我来巡山  阅读(181)  评论(0编辑  收藏  举报

佛祖让我来巡山博客站 - 创建于 2018-08-15

开发工程师个人站,内容主要是网站开发方面的技术文章,大部分来自学习或工作,部分来源于网络,希望对大家有所帮助。

Bootstrap中文网