想抓取这个网站的剩余库存数量
http://www.beibei.com/detail/105272.html
使用fopen(),然后再读取的源代码中,显示的库存量为0,查了资料说需要伪装HTTP,不知道怎么弄,在线等大牛~~~
file_get_contents(); 获取源码后再用正则过滤。
版主,里面的库存量用这个方法抓取到的是- 空的·····
已解出:
<?php// 获取页面内容$content = file_get_contents('http://www.beibei.com/detail/105272.html');// 获取hxcsrfpreg_match('/g.__t__ = \"(.*)\";/U', $content, $matches);$hxcsrf = $matches[1];// 获取idpreg_match('/pageData.encryptId = \'(.*)\';/U', $content, $matches);$id = $matches[1];// post 到 api 获取sku$skuapi = 'http://www.beibei.com/item/detail/get_sku.html';$postdata = http_build_query ( array( 'hxcsrf' => $hxcsrf, 'id' => $id ));$opts = array( 'http' => array( 'method' => 'POST' , 'header' => 'Content-type: application/x-www-form-urlencoded' , 'content' => $postdata ));$context = stream_context_create($opts);$sku = file_get_contents($skuapi, false, $context);$result = json_decode($sku, true);echo '<meta http-equiv="content-type" content="text/html;charset=utf-8">';echo '<pre class="brush:php;toolbar:false;">';print_r($result);echo '
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号