我有这段代码:
include('./simplehtmldom/simple_html_dom.php');
$url = "http://www.turismovenezia.it/Dove-Alloggiare/1322597142.html";
$ch = curl_init();
// set URL and other appropriate options
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// grab URL and pass it to the browser
$output = curl_exec($ch);
//close connection
curl_close($ch);
但我没有得到任何输出..我期待页面的代码($ url)。
有什么想法吗?
哈维
答案 0 :(得分:4)
易于使用:
<?php
echo file_get_contents("http://www.turismovenezia.it/Dove-Alloggiare/1322597142.html");
?>
但测试了这个功能,测试并运行,如果在http://4rapiddev.com/php/php-get-webpage-content-using-curl/上找到:
function get_webpage_content($webpage_url)
{
$curl_handle=curl_init();
curl_setopt($curl_handle,CURLOPT_URL,$webpage_url);
curl_setopt($curl_handle,CURLOPT_TIMEOUT,10);
curl_setopt($curl_handle,CURLOPT_USERAGENT,'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13');
curl_setopt($curl_handle,CURLOPT_CONNECTTIMEOUT,10);
curl_setopt($curl_handle,CURLOPT_RETURNTRANSFER,1);
$html = curl_exec($curl_handle);
curl_close($curl_handle);
return $html;
}
也许你必须使用1而不是真,但我认为你可以使用它们。
答案 1 :(得分:1)
$content = file_get_contents("http://www.turismovenezia.it/Dove-Alloggiare/1322597142.html");
$path = "PATH WHERE YOU HAVE TO STORE";
file_put_contents($content,$path);
答案 2 :(得分:0)
永远不要将file_get_contents用于远程文件,它速度慢,效率低,占用大量CPU资源。使用Curl或fsocket代替... fsocket是两者中最好的。