如何在http://www.example-webpage.com/file.html不使用的情况下获取html源代码file_get_contents()?
我需要知道这一点,因为在某些webhosts allow_url_fopen被禁用,所以你不能使用file_get_contents().是否可以使用cURL获取html文件的源代码(如果启用了cURL支持)?如果是这样,怎么样?谢谢.
我想用cURL 访问https://graph.facebook.com/19165649929?fields=name(显然它也可以用"http"访问)来获取文件的内容,更具体:我需要"名字"(它是json) .由于我的网络服务器上禁用了allow_url_fopen,因此我无法使用get_file_contents!所以我这样试了:
<?php
$page = 'http://graph.facebook.com/19165649929?fields=name';
$ch = curl_init();
//$useragent="Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1";
//curl_setopt($ch, CURLOPT_USERAGENT, $useragent);
curl_setopt($ch, CURLOPT_URL, $page);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_exec($ch);
curl_close($ch);
?>
Run Code Online (Sandbox Code Playgroud)
使用该代码,我得到一个空白页面!当我使用其他页面时,例如http://www.google.com,它就像一个魅力(我得到了页面的内容).我猜facebook正在检查一些我不知道的东西......它有什么用?如何使代码工作?谢谢!
我已经打开了一个HTML文件
file_get_contents('http://www.example.com/file.html')
Run Code Online (Sandbox Code Playgroud)
并想要解析包括"ParseThis"的行:
<h1 class=\"header\">ParseThis<\/h1>
Run Code Online (Sandbox Code Playgroud)
如您所见,它位于h1标记内(h1文件中的第一个标记).如何获得"ParseThis"文本?