欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

想用PHP抓取某网站库存数据

程序员文章站 2022-04-17 11:36:56
...
想抓取这个网站的剩余库存数量
http://www.beibei.com/detail/105272.html
使用fopen(),然后再读取的源代码中,显示的库存量为0,查了资料说需要伪装HTTP,不知道怎么弄,在线等大牛~~~


回复讨论(解决方案)

file_get_contents(); 获取源码后再用正则过滤。

版主,里面的库存量用这个方法抓取到的是- 空的·····

已解出:

 $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 '';echo '
';print_r($result);echo '
';?>


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
)

)

)