|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
import requests
import os
import re
url = 'https://search.bilibili.com/all?keyword=python&from_source=nav_suggest_new&page='
headers = {'user-agent':'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36'
}
page = 1
url = url+str(page)
res = requests.get(url=url,headers = headers )
html = res.text
data = re.findall('<li class="video-item matrix"><a href="//(.*?)" title=".*?" target="_blank" class="img-anchor">',html)
video = data[0]
# print(video) # 输出结果: www.bilibili.com/video/BV1xs411Q799?from=search
filename = 'python'+'.mp4'
#for i in data:
# print(i)
with open ('python视频教程爬取'+'/'+filename,mode='wb' ) as f:
res = requests.get (url = video ,headers = headers )
f.write(res.content)
错误提示:
www.bilibili.com/video/BV1xs411Q799?from=search
Traceback (most recent call last):
File "D:/python/project/python视频教程爬取.py", line 30, in <module>
res = requests.get (url = video ,headers = headers )
File "C:\Users\handsome\AppData\Local\Programs\Python\Python38\lib\site-packages\requests\api.py", line 76, in get
return request('get', url, params=params, **kwargs)
File "C:\Users\handsome\AppData\Local\Programs\Python\Python38\lib\site-packages\requests\api.py", line 61, in request
return session.request(method=method, url=url, **kwargs)
File "C:\Users\handsome\AppData\Local\Programs\Python\Python38\lib\site-packages\requests\sessions.py", line 516, in request
prep = self.prepare_request(req)
File "C:\Users\handsome\AppData\Local\Programs\Python\Python38\lib\site-packages\requests\sessions.py", line 449, in prepare_request
p.prepare(
File "C:\Users\handsome\AppData\Local\Programs\Python\Python38\lib\site-packages\requests\models.py", line 314, in prepare
self.prepare_url(url, params)
File "C:\Users\handsome\AppData\Local\Programs\Python\Python38\lib\site-packages\requests\models.py", line 388, in prepare_url
raise MissingSchema(error)
requests.exceptions.MissingSchema: Invalid URL 'www.bilibili.com/video/BV1xs411Q799?from=search': No schema supplied. Perhaps you meant http://www.bilibili.com/video/BV1xs411Q799?from=search?
保存不了, video 输出的结果就已经是视频的地址了 (点击该结果 就会跳转到 该视频播放页面。)
如果对你有帮助记得设置最佳哈~~~
|
|