how to – 用php抓取iTunes Store的搜索结果
星期六, 八月 6th, 2011从iTunes Store中copy出来的链接无法直接在浏览器中打开,google之,有人已经用php+curl做了相关工作,只要在http header中加上一个参数即可
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | function htmlForiTunesStoreURL($path) // Download and return the HTML for an iTunes Store page at the given URL. { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $path); // The following header is what causes the server to think we are iTunes.app. // This header in particular is for the China Store. curl_setopt($ch, CURLOPT_HTTPHEADER, array('X-Apple-Store-Front: 143465-19,12')); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $html = curl_exec($ch); return trim($html); } |
其中X-Apple-Store-Front: 143465-19,12,143465是中国的iTunes Store代码,-19,12不知道什么意思,这是用截取http封包的工具截出来的,-19的位置是语言代码,但网上搜索不到中文代码是什么,也许就是19
以下是其他国家的代码:
United States 143441
Argentina 143505
Australia 143460
Belgium 143446
Brazil 143503
Canada 143455
Chile 143483
China 143465
Colombia 143501
Costa Rica 143495
Croatia 143494
Czech Republic 143489
Denmark 143458
Deutschland 143443
El Salvador 143506
Espana 143454
Finland 143447
France 143442
Greece 143448
Guatemala 143504
Hong Kong 143463
Hungary 143482
India 143467
Indonesia 143476
Ireland 143449
Israel 143491
Italia 143450
Korea 143466
Kuwait 143493
Lebanon 143497
Luxembourg 143451
Malaysia 143473
Mexico 143468
Nederland 143452
New Zealand 143461
Norway 143457
Osterreich 143445
Pakistan 143477
Panama 143485
Peru 143507
Phillipines 143474
Poland 143478
Portugal 143453
Qatar 143498
Romania 143487
Russia 143469
Saudi Arabia 143479
Schweitz/Suisse 143459
Singapore 143464
Slovakia 143496
Slovenia 143499
South Africa 143472
Sri Lanka 143486
Sweden 143456
Taiwan 143470
Thailand 143475
Turkey 143480
United Arab Emirates 143481
United Kingdom 143444
Venezuela 143502
Vietnam 143471
Japan 143462
关于第二位数字的解释
1: English
2: English (slightly different texts)
3: French
4: German
5: French (slightly different texts)
现在可以就可以正常获得数据了,如
1 2 3 | echo htmlForiTunesStoreURL( "http://ax.search.itunes.apple.com/WebObjects/MZSearch.woa/wa/advancedSearch?startIndex=180&entity=software&media=software&page=2&restrict=true&free=1&genreIndex=10" ); |