只需使用pytube模块网站上的示例代码即可。我已经安装了pytube。我也试过通过在命令行中进入python来运行它。尝试输入此
时出现同样的错误yt = YouTube("YouTube/Link")
(代码下面的错误)
from pytube import YouTube
from pprint import pprint
yt = YouTube("http://www.youtube.com/watch?v=Ik-RsDGPI5Y")
pprint(yt.get_videos())
print(yt.filename)
yt.set_filename('Pulp_Fiction.mp4')
print(yt.filter('mp4')[-1])
pprint(yt.filter(resolution='720p'))
video = yt.get('mp4', '720p')
pprint(yt.videos)
video.download('/home/jralph/')
错误....
(venv) MY-MBP:new ME$ python3 yt.py
Traceback (most recent call last):
File "yt.py", line 4, in <module>
yt = YouTube("http://www.youtube.com/watch?v=Ik-RsDGPI5Y")
File "/Users/MY/new/venv/lib/python3.4/site-packages/pytube/api.py", line 66, in __init__
self.from_url(url)
File "/Users/MY/new/venv/lib/python3.4/site-packages/pytube/api.py", line 189, in from_url
signature = self._get_cipher(stream_map["s"][i], js_url)
File "/Users/MY/new/venv/lib/python3.4/site-packages/pytube/api.py", line 363, in _get_cipher
response = urlopen(url)
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/urllib/request.py", line 161, in urlopen
return opener.open(url, data, timeout)
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/urllib/request.py", line 462, in open
req = meth(req)
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/urllib/request.py", line 1106, in do_request_
raise URLError('no host given')
urllib.error.URLError: <urlopen error no host given>
(venv) MYs-MBP:new ME$