python爬视频实例

python爬视频实例,第1张

概述例:抓取PhotoShop视频教程 网址http://www.mxiaobei.com/?id=424 import requestsimport refrom bs4 import BeautifulSoupimport timedicts = {}list1 = set()print('start')ua = 'Mozilla/5.0 (Macintosh; Intel M

例:抓取PhotoShop视频教程 网址http://www.mxiaobei.com/?ID=424

import requestsimport refrom bs4 import BeautifulSoupimport timedicts = {}List1 = set()print('start')ua = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_0) AppleWebKit/537.36 (KHTML,like Gecko) Chrome/76.0.3809.87 Safari/537.36'urls = 'http://www.mxiaobei.com/?ID='for index in range(451,565):    r = requests.get(urls + str(index),headers = {'user-agent': ua })    r.enCoding = 'utf-8'    soup = BeautifulSoup(r.text,'lxml')    Title = soup.find(name='h2')    mp4url = soup.find('div',ID='CuPlayer')    if mp4url is None:        List1.add(index)        continue    mpurl = re.search('http.*?mp4',mp4url.text)    dicts[Title.text] = mpurl.group()    #print(index)    #time.sleep(1)    #print(Title.text + ' : ' + dicts[Title.text])print(dicts)print(List1)for temp in dicts.items():    #time.sleep(1)    r = requests.get(temp[1],stream=True)    with open(temp[0] + '.mp4',"wb") as mp4:        for chunk in r.iter_content(chunk_size=1024 * 1024):            if chunk:                mp4.write(chunk)    print(temp[0]+'下载完成')print('end!')
BeautifulSoup: https://beautifulsoup.readthedocs.io/zh_CN/v4.4.0/ Requests: http://cn.python-requests.org/zh_CN/latest/ 总结

以上是内存溢出为你收集整理的python爬视频实例全部内容,希望文章能够帮你解决python爬视频实例所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/1195415.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-03
下一篇 2022-06-03

发表评论

登录后才能评论

评论列表(0条)

保存