爬取梨视频
#categoryId=9 分类id
#start=0 从哪个位置开始,每次加载12个
# https://www.pearvideo.com/category_loading.jsp?reqType=5&categoryId=9&start=0
import requests
import re
ret = requests.get('https://www.pearvideo.com/category_loading.jsp?reqType=5&categoryId=3&start=3')
# print(ret.text)
# 正则解析
reg = '<a href="(.*?)" class="vervideo-lilink actplay">'
video_urls = re.findall(reg, ret.text)
print(video_urls)
for url in video_urls:
ret_detail = requests.get('https://www.pearvideo.com/'+url)
# print(ret_detail.text)
# break
reg = 'srcUrl="(.*?)",vdoUrl=srcUrl'
mp4_url = re.findall(reg, ret_detail.text)[0]
# print(mp4_url)
# break
# 下载视频
video_content = requests.get(mp4_url)
video_name = mp4_url.rsplit('/', 1)[1]
with open(video_name, 'wb') as f:
for line in video_content.iter_content():
f.write(line)