サーバは、ユーザエージェントがQTの場合にのみビデオにアクセスできます。このスクリプトに追加するにはどうすればいいですか?PythonスクリプトでQuickTimeとしてuseragentを設定する方法は?
#!/usr/bin/env python
from os import pardir, rename, listdir, getcwd
from os.path import join
from urllib import urlopen, urlretrieve, FancyURLopener
class MyOpener(FancyURLopener):
version = 'QuickTime/7.6.2 (verqt=7.6.2;cpu=IA32;so=Mac 10.5.8)'
def main():
# Set up file paths.
data_dir = 'data'
ft_path = join(data_dir, 'titles.txt')
fu_path = join(data_dir, 'urls.txt')
# Open the files
try:
f_titles = open(ft_path, 'r')
f_urls = open(fu_path, 'r')
except:
print "Make sure titles.txt and urls.txt are in the data directory."
exit()
# Read file contents into lists.
titles = []
urls = []
for l in f_titles:
titles.append(l)
for l in f_urls:
urls.append(l)
# Create a dictionary and download the files.
downloads = dict(zip(titles, urls))
for title, url in downloads.iteritems():
fpath = join(data_dir, title.strip().replace('\t',"").replace(" ", "_"))
fpath += ".mov"
urlretrieve(url, fpath)
if __name__ == "__main__": main()
これを無視して、転記の制限を満たすテキストを入力してください。直接urllibは使用するのではなく、
opener = MyOpener()
opener.retrieve(url, fpath)
を、それはトリックを行う必要があります。
http://wolfprojects.altervista.org/changeua.php
が次に試してみてください。blablablablaは
私はPythonをまったく知らない... – WaterBearer
私は次のようにしましたが、ファイルはまだ 'urllib import urlopen、urlretrieve、FancyURLopenerからダウンロードされていません。class MyOpener(FancyURLopener): \t version = 'QuickTime/7.6.2(verqt = 7.6.2; cpu = IA32 ; so = Mac 10.5.8) '' – WaterBearer
あなたがやっていることを完全なソースcod eに投稿してください - それ以外の場合は手助けができません –