在 PHP 中查看 firmy.cz 的源代码 (html) 代码(没有任何效果)



请告诉我:如何在PHP中查看此URL的源代码:https://www.firmy.cz/Remesla-a-sluzby/Bezpecnostni-sluzby?_escaped_fragment_=?我测试了 7 种变体。它们都不起作用。

有些代码显示奇怪的代码(不可读的字符(,请参阅下面 php 脚本中的注释。这个网站是否有可能以某种方式防止通过 php 读取代码?对于其他站点,这些脚本可以正常工作。

将ISO更改为UTF(iso2utf(的功能也不起作用。

以下方法均无效:

<?php
$link="https://www.firmy.cz/Remesla-a-sluzby/Bezpecnostni-sluzby?_escaped_fragment_=";
// TEST 1:
function get_dataa($url) {
  $ch = curl_init();
  $timeout = 5;
  curl_setopt($ch, CURLOPT_URL, $url);
  curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0)");
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  curl_setopt($ch, CURLOPT_SSL_VERIFYHOST,false);
  curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,false);
  curl_setopt($ch, CURLOPT_MAXREDIRS, 10);
  curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
  curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
  $data = curl_exec($ch);
  curl_close($ch);
  return $data;
}
$html = get_dataa($link);
echo $html;
// return ��[�Z���]sG�&|m��n�lw...

// TEST 2:
$html = readfile($link);
echo $html;
//return ��[�Z���]sG�&|m��n�lw,���[�C��...

// TEST 3:
include_once('simple_html_dom.php');
$html = file_get_html($link);
echo htmlspecialchars($html);
//return empty

// TEST 4:
$c = curl_init($link);
curl_setopt($c, CURLOPT_RETURNTRANSFER, true);
$html = curl_exec($c);
if (curl_error($c))
    die(curl_error($c));
$status = curl_getinfo($c, CURLINFO_HTTP_CODE);
curl_close($c);
echo htmlspecialchars($html);
//return epmty


// TEST 5:
$html = file_get_contents($link);
echo htmlspecialchars($html);
//return epmty

// TEST 6:
$src=file($link);
print_r($src);
// return: Array ( [0] => ��[�Z���]sG�&|m��n�lw,���[�C��lK∲�ۻ�P$J��@"��......

// TEST 7:
$src=file($link);
$html="";
for($i=0; $i<5000; $i++){
$html.=iso2utf($src[$i]);
}
echo htmlspecialchars($html);
// return: ď[ÉZ˙í˝]sG&|mýnôlw,Ô÷[C¤äślKⲝ۝P$JŞĐ@"šŃs9Ó .....

因为页面是压缩的,所以你需要使用这个php函数:http://php.net/manual/en/function.gzdecode.php

以简单的方式:

$link="https://www.firmy.cz/Remesla-a-sluzby/Bezpecnostni-sluzby?_escaped_fragment_=";
function get_dataa($url) {
  $content = file_get_contents($url);
  return gzdecode($content); 
}
echo get_dataa($link);

最终解决方案:

function get_dataa($url) {
  $content=file_get_contents($url);
   $ch = curl_init($url); 
   curl_setopt($ch, CURLOPT_NOBODY, 1); 
   curl_setopt($ch, CURLOPT_HEADER, 1); 
   curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);  
   $output = curl_exec($ch); 
   curl_close($ch);  
   if(strpos(" ".$output, "gzip")){ $content=gzdecode($content); }
  return $content; 
}

最新更新