我試圖從tweet中獲取視頻網址,A
來自tweepy。由於Twitter不知道哪一個是最高質量的視頻,我假設我必須比較最高的「比特率」並存儲與其相對應的「網址」。這是我的。從列表中獲取正確的數據
請耐心等待,我是新手。
A = [{'content_type': 'application/x-mpegURL', 'url': 'https://video.twimg.com/ext_tw_video/758995712280412672/pu/pl/X_6gAm0z8TBBbEAR.m3u8'},
{'bitrate': 832000, 'content_type': 'video/mp4', 'url': 'https://video.twimg.com/ext_tw_video/758995754280412672/pu/vid/360x640/6nxKFKpdku-qAl__.mp4'},
{'content_type': 'application/dash+xml', 'url': 'https://video.twimg.com/ext_tw_video/758995715280412672/pu/pl/X_6gAm0z8TBBbEAR.mpd'},
{'bitrate': 320000, 'content_type': 'video/mp4', 'url': 'https://video.twimg.com/ext_tw_video/758995715280412672/pu/vid/180x320/VqRF6IcnmsLxZIil.mp4'}]
for i, val in enumerate(A):
if 'bitrate' in A[i]:
print(A[i]['bitrate'], A[i]['url'])
這段代碼產生
832000 https://video.twimg.com/ext_tw_video/758996713280412672/pu/vid/360x640/6nxKFKpdku-qAl__.mp4
320000 https://video.twimg.com/ext_tw_video/758997716280412672/pu/vid/180x320/VqRF6IcnmsLxZIil.mp4
如何存放的[ '網址']與最高[ '比特率']對應到一個變量?
那麼,什麼是你的問題嗎? –
max(A,key = lambda x:x ['bitrate'])? –
@IronFist對不起,我應該說清楚,如何將['url']與最高['bitrate']對應的值存儲到變量中? –