要素を抽出して配列から変数に割り当てようとしましたが、次のエラーが発生しました。
Traceback (most recent call last):
File "test.py", line 12, in <module>
itag_start = element.find(itag)
AttributeError: 'Stream' object has no attribute 'find'
これは私のコードです
from pytube import YouTube
link = YouTube('http://youtube.com/watch?v=9bZkp7q19f0')
array = link.streams.all()
itag = 'itag'
mime_type='mime_type'
res='res'
counter = 0
iv = []
mt = []
re = []
for element in array :
itag_start = element.find(itag)
if itag_start != -1:
itag_end = element.find('"', itag_start+len(itag)+2)
itag_value = element[itag_start+len(itag)+1:itag_end+1]
iv.insert(counter,itag_value)
mime_type_start = element.find(mime_type)
if mime_type_start != -1:
mime_type_end = element.find('"', mime_type_start+len(mime_type)+2)
mime_type_value = element[mime_type_start+len(mime_type)+1:mime_type_end+1]
mt.insert(counter,mime_type_value)
res_start = element.find(res)
if res_start != -1:
res_end = element.find('"', res_start+len(res)+2)
res_value = element[res_start+len(res)+1:res_end+1]
re.insert(counter,res_value)
counter = counter + 1
ただし、 link.streams.all() を出力に直接置き換えると、エラーはなくなります。
[<Stream: itag="22" mime_type="video/mp4" res="720p" fps="30fps" vcodec="avc1.64001F" acodec="mp4a.40.2">,
<Stream: itag="43" mime_type="video/webm" res="360p" fps="30fps" vcodec="vp8.0" acodec="vorbis">,
<Stream: itag="18" mime_type="video/mp4" res="360p" fps="30fps" vcodec="avc1.42001E" acodec="mp4a.40.2">,
<Stream: itag="36" mime_type="video/3gpp" res="240p" fps="30fps" vcodec="mp4v.20.3" acodec="mp4a.40.2">,
<Stream: itag="17" mime_type="video/3gpp" res="144p" fps="30fps" vcodec="mp4v.20.3" acodec="mp4a.40.2">,
<Stream: itag="137" mime_type="video/mp4" res="1080p" fps="30fps" vcodec="avc1.640028">,
<Stream: itag="248" mime_type="video/webm" res="1080p" fps="30fps" vcodec="vp9">,
<Stream: itag="136" mime_type="video/mp4" res="720p" fps="30fps" vcodec="avc1.4d401f">,
<Stream: itag="247" mime_type="video/webm" res="720p" fps="30fps" vcodec="vp9">,
<Stream: itag="135" mime_type="video/mp4" res="480p" fps="30fps" vcodec="avc1.4d401e">,
<Stream: itag="244" mime_type="video/webm" res="480p" fps="30fps" vcodec="vp9">,
<Stream: itag="134" mime_type="video/mp4" res="360p" fps="30fps" vcodec="avc1.4d401e">,
<Stream: itag="243" mime_type="video/webm" res="360p" fps="30fps" vcodec="vp9">,
<Stream: itag="133" mime_type="video/mp4" res="240p" fps="30fps" vcodec="avc1.4d4015">,
<Stream: itag="242" mime_type="video/webm" res="240p" fps="30fps" vcodec="vp9">,
<Stream: itag="160" mime_type="video/mp4" res="144p" fps="30fps" vcodec="avc1.4d400c">,
<Stream: itag="278" mime_type="video/webm" res="144p" fps="30fps" vcodec="vp9">,
<Stream: itag="140" mime_type="audio/mp4" abr="128kbps" acodec="mp4a.40.2">,
<Stream: itag="171" mime_type="audio/webm" abr="128kbps" acodec="vorbis">,
<Stream: itag="249" mime_type="audio/webm" abr="50kbps" acodec="opus">,
<Stream: itag="250" mime_type="audio/webm" abr="70kbps" acodec="opus">,
<Stream: itag="251" mime_type="audio/webm" abr="160kbps" acodec="opus">]
これを修正する方法について何か考えはありますか?