亚洲城娱乐phpQuery获取网页里的js变量,如何获取

( 亚洲城娱乐 )

获取: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>

没用过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"
    }
*/

(看完/读完)这篇文章有何感想! 亚洲城娱乐的分享…

发表评论

电子邮件地址不会被公开。 必填项已用*标注