批量爬取梨视频(基础版)
批量下载小视频,不到40行代码
没有添加函数,因为我是小白
应该大部分的鱼油都能看懂,路过的朋友给个支持呗{:5_95:}
import requests
import parsel
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.25 Safari/537.36 Core/1.70.3760.400 QQBrowser/10.5.4083.400'
}
target = "https://www.pearvideo.com/"
page = 1
for i in range(10,50,10):
print("====================开始下载第%d页==========================="%page)
page += 1
url = "https://www.pearvideo.com/popular_loading.jsp?reqType=1&categoryId=8&start={}".format(i)
res = requests.get(url,headers=headers)
res.encoding="utf-8"
html = parsel.Selector(res.text)
lists = html.xpath('//li/a/@href').getall()
for each in lists:
links = target + each
print("下载链接为:",links)
response = requests.get(url=links,headers=headers)
response.encoding="utf-8"
htmls = parsel.Selector(response.text)
content = htmls.re('srcUrl="(.*?)",vdoUrl=')
name = htmls.re('<title>(.*?)-梨视频官网-Pear Video</title>')
#print("开始下载视频:",name)
for names in name:
for video in content:
#vs = video.split("/")[-1]
videos = requests.get(url=video,headers=headers)
f_name = names + ".mp4"
with open(str(f_name),"wb") as f:
f.write(videos.content) 居然沉了{:5_107:} {:10_256:}
页:
[1]