Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/227.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从网站地图中删除所有iFrame src_Php_Arrays_Simple Html Dom - Fatal编程技术网

php从网站地图中删除所有iFrame src

php从网站地图中删除所有iFrame src,php,arrays,simple-html-dom,Php,Arrays,Simple Html Dom,我正在尝试创建一个网站,以便创建其中所有iFrame源代码的列表,为此,我使用simple_html_dom php库 我解析每个链接,在搜索iframe的每个链接中,我发现iframe存在,我要求代码向我提供它的src和它从中获取的页面 我正在做的是: 抓取所需页面中的所有链接 将它们转换为一个大阵列,以避免服务器崩溃 所有链接都是相对的,所以我在开头添加了主url 我循环所有URL并在页面中搜索iFrame 结果是,它对20行运行良好,然后我得到以下错误: Warning: file_get

我正在尝试创建一个网站,以便创建其中所有iFrame源代码的列表,为此,我使用simple_html_dom php库

我解析每个链接,在搜索iframe的每个链接中,我发现iframe存在,我要求代码向我提供它的src和它从中获取的页面

我正在做的是:

  • 抓取所需页面中的所有链接

  • 将它们转换为一个大阵列,以避免服务器崩溃

  • 所有链接都是相对的,所以我在开头添加了主url
  • 我循环所有URL并在页面中搜索iFrame
  • 结果是,它对20行运行良好,然后我得到以下错误:

    Warning: file_get_contents(): php_network_getaddresses: getaddrinfo failed: No such host is known. in C:\xampp\htdocs\scrap\simple_html_dom.php on line 75
    
    Warning: file_get_contents(http://www.achva.ac.ilhttp://www.achva.ac.il/לימודי-תעודה-והשתלמויות): failed to open stream: php_network_getaddresses: getaddrinfo failed: No such host is known. in C:\xampp\htdocs\scrap\simple_html_dom.php on line 75
    
    Fatal error: Call to a member function find() on a non-object in C:\xampp\htdocs\scrap\scrap.php on line 61
    
    出于某种原因,我不断地出现错误:

    这是我的代码:

        <!DOCTYPE html>
    <html>
    <head>
        <title></title>
    
        <style type="text/css">
            th{
                font-weight: 800;
                border: 1px solid lightblue;
            }
            td{
                border: 1px solid lightblue;
            }
        </style>
    </head>
    <body>
    <?php 
    
    $html = file_get_contents('http://www.achva.ac.il/sitemap');
    //Create a new DOM document
    $dom = new DOMDocument;
    
    //Parse the HTML. The @ is used to suppress any parsing errors
    //that will be thrown if the $html string isn't valid XHTML.
    @$dom->loadHTML($html);
    
    //Get all links. You could also use any other tag name here,
    //like 'img' or 'table', to extract other tags.
    $links = $dom->getElementsByTagName('a');
    
    //Iterate over the extracted links and display their URLs
    $arr = [];
    foreach ($links as $link){
        array_push($arr, 'http://www.achva.ac.il'.$link->getAttribute('href'));
    }
    
    
    $result = count($arr);
    echo $result;
    ?>
    
    <?php  
    
    
    function urlOk($url) {
        $headers = @get_headers($url);
        if($headers[0] == 'HTTP/1.1 200 OK') return true;
        else return false;
    }
    
    */
    include('simple_html_dom.php');
    
    echo '<table><tr><th>id</th><th>Video src</th><th>Site page</th></tr>';
    $i = 19;
    $page_number = 1;
    
    foreach($arr as $urlx){
    
        echo $urlx;
    
            $scrap_url = file_get_html($urlx);
    
            if (preg_match('#^http?://(?:[^.]+\.)*achva\.ac.il/#i', $urlx))     
            {
    
    
            $div = $scrap_url->find('iframe');
            if($div){
    
                foreach ($div as $key) {
    
                    echo '<tr><td>' . $i . '</td>';
    
                    $src = $key->attr['src'];
                    echo '<td>' . $src . '</td>';
                    echo '<td>' .$urlx . '</td></tr>';
                    $page_number++;
    
                }
    
            }else{
                echo '<tr><td>' . $i . '</td><td>no iframe in this tage</td><td>' . $urlx . '</td></tr>';
    
            }
    
            $i++;
        }
    }
    ?>
    </table>
    </body>
    </html>
    
    
    th{
    字号:800;
    边框:1px纯色浅蓝色;
    }
    运输署{
    边框:1px纯色浅蓝色;
    }
    
    也许这是你正在抓取的页面中的一个不可靠的链接?我尝试用“如果(preg#u match(''.^http?:/(?:[^.]+\)*achva\.ac.il/.\35; I',$urlx)]”这一行来避免坏的URL。“我不知道是什么导致了这个问题……从语法角度来看可能是一个有效的链接,但实际上并不存在?”?因此,当您尝试获取它时,会出现一个连接错误,例如您看到的错误您是对的,存在一个不可靠的链接,我添加了此函数以避免它,
    if(preg_match('http://www.achva.ac.il“,$link”){array_push($arr,$link->getAttribute('href');}else{array_push($arr,'http://www.achva.ac.il“.$link->getAttribute('href');}
    不管怎样,它在20行之后仍然会停止,它仍然会以相同的错误停止?也许这是您正在抓取的页面中的一个不可靠链接?我尝试使用“if”(preg#u match('.^http?:/(?:[^.]+\)*achva\.ac.il/#I',$urlx))行避免错误的URL)“我不知道是什么导致了这个问题……从语法的角度来看,可能是一个有效的链接,但实际上并不存在?因此,当你试图获取它时,你会遇到一个连接错误,比如你认为你是对的,有一个不可靠的链接,我添加这个函数是为了避免它,
    if(preg_-match('http://www.achva.ac.il“,$link”){array_push($arr,$link->getAttribute('href');}其他{array_push($arr,'http://www.achva.ac.il'.$link->getAttribute('href');}
    在第20行之后,它是否仍会停止,并出现相同的错误?