Home > Backend Development > PHP Tutorial > 怎么获取远程网页的html代码,file_get_contents不起作用

怎么获取远程网页的html代码,file_get_contents不起作用

WBOY
Release: 2016-06-13 10:26:41
Original
987 people have browsed it

如何获取远程网页的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);});<br><font color="#e78608">------解决方案--------------------</font><br>
Copy after login
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));<div class="clear">
                 
              
              
        
            </div>
Copy after login
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template