谁有人帮助我PHP图像刮刀?

时间:2017-02-09 09:16:27

标签: php html arrays image scraper

当我一次做一个网站时效果很好但是当我一次做多时我得到以下错误:

  

警告:file_get_contents():php_network_getaddresses:getaddrinfo   失败:主机正在进行中。在   第76行的C:\ xampp \ htdocs \ blabla \ simple_html_dom.php

     

警告:file_get_contents(https://www.google.nl):无法打开   stream:php_network_getaddresses:getaddrinfo failed:Host is   onbekend。在第76行的C:\ xampp \ htdocs \ blabla \ simple_html_dom.php

     

致命错误:在非对象中调用成员函数find()   第21行的C:\ xampp \ htdocs \ blabla \ backend.php

这是我的图像刮刀:

<?php
    if (isset($_POST["submit"])) {
        $notes = explode("\n", $_POST['linkjes']);

        foreach ($notes as $link) {
            x($link);
        }
    }
    else
    {
        echo "je hoort hier niet";
    }


    function x($link){

    $file = 'images.txt';
    $current = file_get_contents($file);
    include_once 'simple_html_dom.php';

    $html = file_get_html($link);

    foreach($html->find('img') as $element)

        if (strpos($element->src,'.png') !== false) 
        {
            $current .= $element->src."\n";
            file_put_contents($file, $current);
         } 
         else if (strpos($element->src,'.jpg') !== false) 
         {
            $current .= $element->src."\n";
            file_put_contents($file, $current);
         } 
         else if (strpos($element->src,'.gif') !== false) 
         {
                $current .= $element->src."\n";
            file_put_contents($file, $current);
         }
         else if (strpos($element->src,'.ico') !== false) 
         {
                $current .= $element->src."\n";
            file_put_contents($file, $current);
         }
         else if (strpos($element->src,'.jpeg') !== false) 
         {
                $current .= $element->src."\n";
            file_put_contents($file, $current);
         }

    $lines = file($file);
    $lines = array_unique($lines);
    file_put_contents($file, implode($lines));

    }
    ?>

0 个答案:

没有答案
相关问题