我正在学习蜘蛛网站的内容与PHP-file_get_contents,但东西是wrong.The网页我想要的是"http://www.jandan.net“。
但是使用file_get_content(),我从"http://i.jandan.net“获取内容(这是电话页面,它们是不同的页面)。user_agent也无法使用。
<?php
ini_set("user_agent","Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2) Gecko/20100301 Ubuntu/9.10 (karmic) Firefox/3.6");
$url = 'http://www.jandan.net/';
/*
$opt = array( 'http'=>array(
'method'=>"GET",
'header'=>"User-Agent: Mozilla/5.0\n"
)
);
$context = stream_context_create($opt);
*/
$content = file_get_contents($url);
echo var_dump($content);
?>发布于 2013-08-22 00:24:51
您在$content = file_get_contents($url,);中的逗号导致了此问题。
-------------------------------------------------------------------------^
来自original posted code -^
保留逗号将产生以下错误消息:
解析错误:语法错误,意外的')‘在.....(文件夹路径等)
快速笔记:使用$url = 'http://i.jandan.net/';也有效,可以显示内容。
试试这个:
<?php
ini_set("user_agent","Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2) Gecko/20100301 Ubuntu/9.10 (karmic) Firefox/3.6");
$url = 'http://www.jandan.net/';
/*
$opt = array( 'http'=>array(
'method'=>"GET",
'header'=>"User-Agent: Mozilla/5.0\n"
)
);
$context = stream_context_create($opt);
*/
$content = file_get_contents($url);
echo var_dump($content);
// echo $content;
?>https://stackoverflow.com/questions/18362048
复制相似问题