dongzhankou2090 2015-07-21 05:24
浏览 140
已采纳

如何获取特定网址的完整html内容?

I used several method to get html content of aptoide.com in php.

1) file_get_contents();

2) readfile();

3) curl as php function

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 Simple HTML DOM Parser

include_once('simple_html_dom.php');
$url="http://aptoide.com";
$html = file_get_html($url);

But all of them give empty output for aptoide.com Is there a way to get full html content of that url ?

  • 写回答

2条回答 默认 最新

  • douaonong7807 2015-07-21 10:53
    关注

    echo file_get_contents('http://www.aptoide.com/'); works fine for me.

    So it's possible that aptoide.com has been blocked you. If you want to change your IP (as you said in comment) you have to use this:

    $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;
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 用hfss做微带贴片阵列天线的时候分析设置有问题
  • ¥50 我撰写的python爬虫爬不了 要爬的网址有反爬机制
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥120 计算机网络的新校区组网设计
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 海浪数据 南海地区海况数据,波浪数据
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等