1

我必须每天从 iTunes Store 导入 EPF 数据,所以我必须编写一个脚本,首先通过提要 url 对我进行身份验证,然后允许我通过脚本自动下载文件。

但是,我没有找到任何通过 url 验证自己的方法:

http://feeds.itunes.apple.com/feeds/

首先我手动下载它,但现在我希望我的脚本每天下载它。我如何对此进行身份验证?或者还有其他方法可以实现这一目标吗?

任何想法或观点都将受到高度赞赏。

4

2 回答 2

1

我通过 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;

就这么简单:)

于 2011-10-10T10:09:39.570 回答
0

例如,在 python 中,您可以使用该requests ,它可以很好地进行身份验证(并且您可以以更简单的方式编写下载逻辑。它看起来像这样

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()
于 2015-06-11T17:50:27.667 回答