主页 M

python应用正则爬梨视频视频,学习finall应用

2020-03-24 网页编程网 网页编程网
# -*- coding: utf-8 -*-
import requests
import re
url='https://www.pearvideo.com/category_1'

def getList(url):
    response=requests.get(url)
    videoId=re.findall('<a href="(.*?)" class="vervideo-lilink actplay">',response.text)
    for i in videoId:
        getMp4('https://www.pearvideo.com/'+i)
    
def getMp4(url):
    res=requests.get(url)
    title=re.findall('<title>(.*?)</title>',res.text)
    video=re.findall('srcUrl="(.*?)",',res.text)
    res=requests.get(video[0])
    with open('video/{}.mp4'.format(title[0]),'wb') as f:
        f.write(res.content)
        print('{} downed'.format(title[0]))

getList(url)
阅读原文
阅读 3366
123 显示电脑版