Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/238.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何获取特定url的完整html内容?_Php_Dom - Fatal编程技术网

Php 如何获取特定url的完整html内容?

Php 如何获取特定url的完整html内容?,php,dom,Php,Dom,我使用了几种方法在php中获取aptoide.com的html内容 1) file_get_contents() 2) readfile() 3) curl作为php函数 function get_dataa($url) { $ch = curl_init($url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_BINARYTRANSFER, true); curl_s

我使用了几种方法在php中获取aptoide.com的html内容

1)
file_get_contents()

2)
readfile()

3) curl作为php函数

function get_dataa($url) {
   $ch = curl_init($url);
   curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
   curl_setopt($ch, CURLOPT_BINARYTRANSFER, true);
   curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
   curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (compatible; Konqueror/4.0; Microsoft Windows) KHTML/4.0.80 (like Gecko)");
   $data = curl_exec($ch);
   curl_close($ch);
   return $data;
}
4) PHP简单HTML DOM解析器

include_once('simple_html_dom.php');
$url="http://aptoide.com";
$html = file_get_html($url);
但它们都为aptoide.com提供了空输出
有没有办法获取该url的完整html内容?

使用curl get_dataa函数并添加以下行:

curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
因为该页面正在重定向到www.aptide.com 全功能:

function get_dataa($url) {
    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_BINARYTRANSFER, true);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
    curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (compatible; Konqueror/4.0; Microsoft Windows) KHTML/4.0.80 (like Gecko)");
    $data = curl_exec($ch);
    curl_close($ch);
    return $data;
}

使用curl get_dataa函数添加以下行:

curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
因为该页面正在重定向到www.aptide.com 全功能:

function get_dataa($url) {
    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_BINARYTRANSFER, true);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
    curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (compatible; Konqueror/4.0; Microsoft Windows) KHTML/4.0.80 (like Gecko)");
    $data = curl_exec($ch);
    curl_close($ch);
    return $data;
}

echo文件\u获取\u内容('http://www.aptoide.com/');对我来说很好

所以有可能aptoide.com
已经被你屏蔽了。如果您想更改您的IP(如您在评论中所说),您必须使用以下选项:

$url = 'http://aptoide.com.com/';
$proxy = '127.0.0.1:9095'; // Your proxy
// $proxyauth = 'user:password'; // Proxy authentication if required

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_PROXY, $proxy);
//curl_setopt($ch, CURLOPT_PROXYUSERPWD, $proxyauth);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 1);
$curl_scraped_page = curl_exec($ch);
curl_close($ch);

echo $curl_scraped_page;

echo文件\u获取\u内容('http://www.aptoide.com/');对我来说很好

所以有可能aptoide.com
已经被你屏蔽了。如果您想更改您的IP(如您在评论中所说),您必须使用以下选项:

$url = 'http://aptoide.com.com/';
$proxy = '127.0.0.1:9095'; // Your proxy
// $proxyauth = 'user:password'; // Proxy authentication if required

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_PROXY, $proxy);
//curl_setopt($ch, CURLOPT_PROXYUSERPWD, $proxyauth);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 1);
$curl_scraped_page = curl_exec($ch);
curl_close($ch);

echo $curl_scraped_page;

没用。似乎他们已经阻止了卷曲或使用了一些不起作用的方法。似乎他们阻止了curl或使用了一些方法sample
echo file\u get\u contents('http://www.aptoide.com/');非常适合我。你的问题可能是别的。其他URL是否存在此问题?可能
aptoide.com
阻止了您的IP。有没有办法在curl请求中更改我的IP?简单
echo file\u get\u contents('http://www.aptoide.com/');非常适合我。你的问题可能是别的。其他URL是否存在此问题?可能
aptoide.com
阻止了您的IP。有没有办法在curl请求中更改我的IP?