我必须每天从itunes Store导入EPF数据,所以我必须编写一个脚本,它将首先通过提要URL验证我,然后允许我通过脚本自动下载文件。App Store增量EPF数据
但是,我没有发现任何方式,通过URL来验证自己:
http://feeds.itunes.apple.com/feeds/
首先,我手动下载它,但现在我希望我的脚本来每天下载。我可以如何验证自己?或者有任何其他方式来实现这一目标?
任何想法或观点将不胜感激。
我必须每天从itunes Store导入EPF数据,所以我必须编写一个脚本,它将首先通过提要URL验证我,然后允许我通过脚本自动下载文件。App Store增量EPF数据
但是,我没有发现任何方式,通过URL来验证自己:
http://feeds.itunes.apple.com/feeds/
首先,我手动下载它,但现在我希望我的脚本来每天下载。我可以如何验证自己?或者有任何其他方式来实现这一目标?
任何想法或观点将不胜感激。
我通过卷曲做到了,现在我在里面。
$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;
正是这简单得多:)
在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()