The Seven Year Itch.

MENU

爬虫--下载视频

February 4, 2017 • Read: 265 • Python

#-*-coding:utf-8-*-

from bs4 import BeautifulSoup

from urllib import urlretrieve

import requests

import re


def getVideo(page):
    
    res = requests.get('http://www.budejie.com/video/%s' %page)

    soup = BeautifulSoup(res.text,'lxml')

    reg = r'data-mp4="(.*?)"'  #获取属性值(视频)的正则表达式

    for i in re.findall(reg,res.text):
"""
findall函数返回的总是正则表达式在字符串中所有匹配结果的列表,
此处主要讨论列表中“结果”的展现方式,即findall中返回列表中每个元素包含的信息。
"""

        name = i.split("/")[-1]

        print "downloading.......:%s" %name

        urlretrieve(i,"MP4/%s" %name)

for i in range(1,12):

    getVideo(i)
Tags: None
Archives QR Code
QR Code for this page
Tipping QR Code