当前位置:Gxlcms >
PHP教程 >
怎么获取远程网页的html代码,file_get_contents不起作用
怎么获取远程网页的html代码,file_get_contents不起作用
时间:2021-07-01 10:21:17
帮助过:3人阅读
如何获取远程网页的html代码,file_get_contents不起作用
远程地址:http://rate.taobao.com/member_rate.htm?content=1&result=0&from=rate&user_id=281461646&identity=1&rater=0&direction=0&timeLine=-7&callback=shop_rate_list
通过浏览器可以得到,但是通过file_get_contents这个函数却为空,别的还有什么办法?另外得到的数据看着有点像json,但是用json_decode却不能将它转化为数组,求将得到的数据转换数组的方法
------解决方案--------------------那是js种的json和php的json有点区别,用jQuery获取:
JScript code
$.getJSON("http://rate.taobao.com/member_rate.htm?content=1&result=0&from=rate&user_id=281461646&identity=1&rater=0&direction=0&timeLine=-7&callback=shop_rate_list", function(json){
alert("JSON Data: " + json);
});
------解决方案--------------------
PHP code
$con= file_get_contents($url);
$con= preg_replace('/shop_rate_list\((.*)\)/s','$1',$con);
print_r(json_decode(iconv('gbk','utf-8',$con),true));