想用PHP抓取某网站库存数据 file_get_contents(); 获取源码后再用正则过滤。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 已解出:<?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>';print_r($result);echo '</pre>';?>Array( [success] => 1 [data] => Array ( [sku_id_map] => Array ( [3] => Array ( [0] => 15 [1] => 16 [2] => 19 [3] => 20 [4] => 22 [5] => 458 [6] => 459 [7] => 468 ) ) [sku_kv_map] => Array ( [k3] => 颜色 [v15] => 大号B红 [v16] => 大号B黑 [v19] => 大号B绿 [v20] => 大号B粉 [v22] => 小号绿色 [v458] => 小号黑色 [v459] => 小号粉色 [v468] => 小号红色 ) [sku_stock_map] => Array ( [v15] => Array ( [id] => 61788 [stock] => 100 [price] => 9900 [origin_price] => 21800 ) [v16] => Array ( [id] => 61789 [stock] => 100 [price] => 9900 [origin_price] => 21800 ) [v19] => Array ( [id] => 61790 [stock] => 100 [price] => 9900 [origin_price] => 21800 ) [v20] => Array ( [id] => 61791 [stock] => 100 [price] => 9900 [origin_price] => 21800 ) [v22] => Array ( [id] => 61792 [stock] => 100 [price] => 8900 [origin_price] => 19800 ) [v458] => Array ( [id] => 61793 [stock] => 100 [price] => 8900 [origin_price] => 19800 ) [v459] => Array ( [id] => 61794 [stock] => 100 [price] => 8900 [origin_price] => 19800 ) [v468] => Array ( [id] => 61795 [stock] => 100 [price] => 8900 [origin_price] => 19800 ) [v0] => 800 ) )) PHP des加密输入怎么才能和JAVA的des输出一至呢 帮忙写个php mysql 修改字段问题 url rewrite 匹配 高手们快来啊 能把网站放到内存中而不是硬盘上吗? 如何实现别人在博客上播放我网站音乐时,同时打开我网站? 安装MediaWiki问题 【求助】一个查询的代码 想学php? PHP做网站 php 二维数组 php连接sql失败
$content = file_get_contents('http://www.beibei.com/detail/105272.html');// 获取hxcsrf
preg_match('/g.__t__ = \"(.*)\";/U', $content, $matches);
$hxcsrf = $matches[1];// 获取id
preg_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>';
print_r($result);
echo '</pre>';?>
Array
(
[success] => 1
[data] => Array
(
[sku_id_map] => Array
(
[3] => Array
(
[0] => 15
[1] => 16
[2] => 19
[3] => 20
[4] => 22
[5] => 458
[6] => 459
[7] => 468
) ) [sku_kv_map] => Array
(
[k3] => 颜色
[v15] => 大号B红
[v16] => 大号B黑
[v19] => 大号B绿
[v20] => 大号B粉
[v22] => 小号绿色
[v458] => 小号黑色
[v459] => 小号粉色
[v468] => 小号红色
) [sku_stock_map] => Array
(
[v15] => Array
(
[id] => 61788
[stock] => 100
[price] => 9900
[origin_price] => 21800
) [v16] => Array
(
[id] => 61789
[stock] => 100
[price] => 9900
[origin_price] => 21800
) [v19] => Array
(
[id] => 61790
[stock] => 100
[price] => 9900
[origin_price] => 21800
) [v20] => Array
(
[id] => 61791
[stock] => 100
[price] => 9900
[origin_price] => 21800
) [v22] => Array
(
[id] => 61792
[stock] => 100
[price] => 8900
[origin_price] => 19800
) [v458] => Array
(
[id] => 61793
[stock] => 100
[price] => 8900
[origin_price] => 19800
) [v459] => Array
(
[id] => 61794
[stock] => 100
[price] => 8900
[origin_price] => 19800
) [v468] => Array
(
[id] => 61795
[stock] => 100
[price] => 8900
[origin_price] => 19800
) [v0] => 800
) ))