我有以下代码
import urllib
f=open('ondemand.txt','r')
for line in f:
urllib.urlretrieve (line, "1.webm")
理论上,它可以工作,但URL需要一个cookie集。如何在上述方案中进行操作,还是需要转到urllib2
或requests
?
我尝试过如下使用请求:
import requests
f=open('ondemand.txt','r')
cookie = {'nameofcookie': 'valueofcookie'}
for line in f:
response = requests.get(line,cookies=cookie)
print response.text
fName = line.split('/')[-1]
with open('/tmp/'+fName, 'wb') as f:
f.write(response.content)
然而我收到错误:
<?xml version="1.0" encoding="UTF-8"?>
<Error>
<Code>MissingKey</Code>
<Message>Missing Key-Pair-Id query parameter or cookie value</Message>
</Error>
由于