我每天都要从itunes Store导入EPF数据,所以我必须写一个脚本,它将首先通过feed url验证我的身份,然后允许我通过脚本自动下载文件。
但是,我没有找到任何方法来通过url来验证自己:
http://feeds.itunes.apple.com/feeds/首先,我手动下载了它,但现在我希望我的脚本每天都下载它。我该如何验证自己的身份呢?还有没有其他方法可以做到这一点?
任何想法或观点都将受到高度赞赏。
发布于 2011-10-10 18:09:40
我是通过curl完成的,现在我就在其中了。
$username = "username";
$password = "password";
$url = "http://feeds.itunes.apple.com/feeds/";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_USERPWD, "$username:$password");
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, Array("Content-Type: text/xml"));
curl_setopt($ch, CURLOPT_UNRESTRICTED_AUTH, 1);
$output = curl_exec($ch);
curl_close($ch);
echo $output;它很简单:)
发布于 2015-06-12 01:50:28
例如,在python中,你可以使用requests library,它可以很好地完成身份验证(而且你可以用一种更简单的方式来编写下载逻辑。它看起来就像这样
username='yourusernamehere'
password='yourpasswordhere'
response = requests.get('https://feeds.itunes.apple.com/feeds/', auth=(username, password), stream=True)请注意,我使用了stream=True机制,因为您将下载可能无法放入内存的大型文件,您应该像这样使用分块:
with open(local_filename, 'wb') as f:
for chunk in response.iter_content(chunk_size=1024):
if chunk: # filter out keep-alive new chunks
f.write(chunk)
f.flush()https://stackoverflow.com/questions/7708892
复制相似问题