2017-09-19 10 views
0

私はインターネットからpdfファイルをダウンロードしようとしています。Pythonの 'Requests'に相当する 'curl -o'

curl -o test.pdf <url> 

「要求」を使用して取得しようとしましたが、失敗しました。

# Where <url> is the actual URL 
r = requests.get(<url>, stream=True) 
with open("test.pdf", 'wb') as f: 
    f.write(r.content) 

は何上記の私のcurlコマンドと完全に同等では次のようになります。私は、次のようでしたか? documentationから

+0

を '、 'wb') '、typoですか? – eyllanesc

+0

@eyllanescはい、ただ編集しました。ありがとう。 – Michael

+0

'libcurl'は良いpythonバインディングを持っていることに注意してください... – o11c

答えて

0

が、これはあなたが>読み取り - 蒸気書くべきかです:オープン(test.pdfという、 'WB') `や`オープン( "test.pdfという" として

r = requests.get(<url>, stream=True) 
with open(filename, 'wb') as fd: 
    for chunk in r.iter_content(chunk_size=128): 
     fd.write(chunk) 
関連する問題