phpQuery获取网页里的js变量,如何获取
ringa_lee
ringa_lee 2017-04-10 17:46:24
0
1
481

获取:view-source:http://www.dianping.com/shop/...网页里的
window.shop_conifg变量,如何获取?

<script>
window.shop_config={
        userId: 0,
        shopId: 11576689,
        shopName: "优尼牙科",
        cityId: 2,
        power:5,
        shopType:85,
        map:{
            power:5,
        manaScore:0
        },
        licensePics:['http://mss.sankuai.com/v1/mss_bccd2477df9e492ca0baeb67e4eb3491/qualification/8723a20a-a40c-11e3-8fb0-a254baaa25bb?temp_url_sig=c17ff6525cfabce9e5f94b46ca3f9ee5115a1309&temp_url_expires=1479364038',],
    mainCategoryId:182,
     defaultPic:"http://qcloud.dpfile.com/pc/hhF4nWJIwWw4FXmGBaW39dKYr5NdlHLz5G64Lx3QSTypRKzSBzQnLPwzWURFZUAvtOnd3gXQdDYlAqlaVaAFeZ0rYYyiRo_EhzufqWWjTjs.jpg"
    }
</script>
ringa_lee
ringa_lee

ringa_lee

membalas semua(1)
刘奇

没用过phpquery,这里用正则

//$str就当phpquery获取的字符串
$str="<script>
window.shop_config={
        userId: 0,
        shopId: 11576689,
        shopName: \"优尼牙科\",
        cityId: 2,
        power:5,
        shopType:85,
        map:{
            power:5,
        manaScore:0
        },
        licensePics:['http://mss.sankuai.com/v1/mss_bccd2477df9e492ca0baeb67e4eb3491/qualification/8723a20a-a40c-11e3-8fb0-a254baaa25bb?temp_url_sig=c17ff6525cfabce9e5f94b46ca3f9ee5115a1309&temp_url_expires=1479364038',],
    mainCategoryId:182,
     defaultPic:\"http://qcloud.dpfile.com/pc/hhF4nWJIwWw4FXmGBaW39dKYr5NdlHLz5G64Lx3QSTypRKzSBzQnLPwzWURFZUAvtOnd3gXQdDYlAqlaVaAFeZ0rYYyiRo_EhzufqWWjTjs.jpg\"
    }
</script>";

preg_match('#<script>
window.shop_config=([\s\S]*)</script>#',$str,$match);

print_r($match[1]);

/*
{
        userId: 0,
        shopId: 11576689,
        shopName: "优尼牙科",
        cityId: 2,
        power:5,
        shopType:85,
        map:{
            power:5,
        manaScore:0
        },
        licensePics:['http://mss.sankuai.com/v1/mss_bccd2477df9e492ca0baeb67e4eb3491/qualification/8723a20a-a40c-11e3-8fb0-a254baaa25bb?temp_url_sig=c17ff6525cfabce9e5f94b46ca3f9ee5115a1309&temp_url_expires=1479364038',],
    mainCategoryId:182,
     defaultPic:"http://qcloud.dpfile.com/pc/hhF4nWJIwWw4FXmGBaW39dKYr5NdlHLz5G64Lx3QSTypRKzSBzQnLPwzWURFZUAvtOnd3gXQdDYlAqlaVaAFeZ0rYYyiRo_EhzufqWWjTjs.jpg"
    }
*/

Muat turun terkini
Lagi>
kesan web
Kod sumber laman web
Bahan laman web
Templat hujung hadapan