Heim > Backend-Entwicklung > PHP-Tutorial > 想用PHP抓取某网站库存数据

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

WBOY
Freigeben: 2016-06-23 13:57:36
Original
1246 Leute haben es durchsucht

想抓取这个网站的剩余库存数量
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 '
Nach dem Login kopieren
';?>

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
                )

        )

)

Verwandte Etiketten:
Quelle:php.cn
Erklärung dieser Website
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage