PHP速学教程(入门到精通)
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
想抓取这个网站的剩余库存数量
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>';echo '<pre class="brush:php;toolbar:false">';print_r($result);echo '';?>
php免费学习视频:立即学习
踏上前端学习之旅,开启通往精通之路!从前端基础到项目实战,循序渐进,一步一个脚印,迈向巅峰!
已抢7592个
抢已抢97622个
抢已抢15269个
抢已抢54035个
抢已抢198523个
抢已抢88419个
抢