# def getVideo(page): # req = urllib2.Request('http://www.budejie.com/video/'+page) # 传入需要解析的界面地址 # req.add_header('User-Agent','Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36') # html = urllib2.urlopen(req).read() # reg = r'data-mp4="(.*?)"' # # # 这里可以添加一个判断,只要i<20就说明已到达尾页 # for i in re.findall(reg, html): # 下载当前页面的mp4到桌面的文件夹 # print '正在下载%s' %i # filename = i.split("/")[-1] # urllib.urlretrieve(i, "C:/Users/Asus/Desktop/budejie_mp4/" + filename) # # for i in range(1, 101): # getVideo(i)
# 简短版本 for i in range(1, 101): for i in re.findall(r'data-mp4="(.*?)"', urllib2.urlopen(urllib2.Request('http://www.budejie.com/video/%s'%i, headers={'User-Agent':'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36'})).read()): urllib.urlretrieve(i, "C:/Users/Asus/Desktop/budejie_mp4/" + i.split("/")[-1])