1 回答
TA贡献1828条经验 获得超13个赞
随机猜测后,我发现如果您不提供 User-Agent 标头,指定的 API 将不会返回任何项目。
这是我的版本:
<?php
$eop = 0;
$newest = 0;
while($eop == 0) {
$url='https://shopee.ph/api/v2/search_items/?by=ctime&limit=30&match_id=49133756&newest=0&order=desc&page_type=shop&version=2';
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("user-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.132 Safari/537.36"));
$response = curl_exec($ch);
$http = curl_getinfo($ch, CURLINFO_HTTP_CODE);
print_r($response);
curl_close($ch);
if ($http == 200) {
$products = json_decode($response, TRUE);
$items = $products['items'];
if (count($items) > 1 ) {
foreach ($items as $item) {
$id = $item['itemid'];
echo $id . '<br>';
}
} else {
$eop=1;
}
}
$newest = $newest + 30;
}
- 1 回答
- 0 关注
- 75 浏览
添加回答
举报