Problem with Crawler

Asked

Viewed 59 times

1

I’m trying to make a simple crowler that takes the temperature, just for study, I’m using the simple_html_dom to read the page, but in the file_get_html function of the link above, it presents some errors, and I don’t understand why. The codes I use in temperatura.class were taken from that video. I’m even wearing the same link for the search of temperature, changing only the place. Use php 7.2.

(Line 75 will be marked in the code).

1° error:

Warning: file_get_contents(): stream does not support Seeking in C: wamp64 www crowler_php simple_html_dom.php on line 75

2° error:

Warning: file_get_contents(): Failed to Seek to position -1 in the stream in C: wamp64 www crowler_php simple_html_dom.php on line 75

3° error:

Warning: preg_match_all(): Unknown Modifier '>' in C: wamp64 www crowler_php temperature.class.php on line 26

temperature class.:

require_once './simple_html_dom.php';

class Temperatura {

    public function __construct() {
        $this->getTemperatura("http://www.tempoagora.com.br/previsao-do-tempo/sp/Cotia/");
    }

    public function getTemperatura($url){

        $html = file_get_html($url);

        preg_match_all('/<div class=\"item\">(.*?)<\/div/>', $html, $resultado);
        echo '<pre>';
        print_r($resultado);
    }
}

$t = new Temperatura();

The code of simple_html_dom.php is here

  • In the 3rd. error failed to put the / at the end of the regular expression: preg_match_all('/<div class=\"item\">(.*?)<\/div/>/', $html, $resultado);... where you put it in the wrong place after "div": <\/div/>

  • Continued the same mistake..

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.