S
S
Sergey Vladimirovich2018-10-14 19:04:19
PHP
Sergey Vladimirovich, 2018-10-14 19:04:19

Why is this happening in php simple dom?

If I run the code:

ini_set('error_reporting', E_ALL);
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
require_once 'simple_html_dom.php';
function dlPage($href) {

    $curl = curl_init();
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
    curl_setopt($curl, CURLOPT_HEADER, false);
    curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);

    curl_setopt($curl, CURLOPT_URL, $href);
    curl_setopt($curl, CURLOPT_REFERER, $href);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
    curl_setopt($curl, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/533.4 (KHTML, like Gecko) Chrome/5.0.375.125 Safari/533.4");
    $str = curl_exec($curl);
    curl_close($curl);

    // Create a DOM object
    $dom = new simple_html_dom();
    // Load HTML from a string
    $dom->load($str);

    return $dom;
    }

$html = dlPage('https://xn--80aaafhzh1ao7h.xn--80asehdb/contacts');
$json = $html->find('script', 7)->innertext ;
$obj = json_decode($json);
$mail = $obj->email;
echo $mail;

then everything works as it should
But if I do everything the same but through a loop
function dlPage($href) {

    $curl = curl_init();
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
    curl_setopt($curl, CURLOPT_HEADER, false);
    curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);

    curl_setopt($curl, CURLOPT_URL, $href);
    curl_setopt($curl, CURLOPT_REFERER, $href);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
    curl_setopt($curl, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/533.4 (KHTML, like Gecko) Chrome/5.0.375.125 Safari/533.4");
    $str = curl_exec($curl);
    curl_close($curl);

    // Create a DOM object
    $dom = new simple_html_dom();
    // Load HTML from a string
    $dom->load($str);

    return $dom;
    }
  
$lines = file('url.dat');	
foreach ($lines as $key => $value) {
$html = dlPage($value);
$json = $html->find('script', 7)->innertext ;
$obj = json_decode($json);
$mail = $obj->email;
echo $mail;
  
}

I can't get the same line and swears at this:
Notice: Trying to get property of non-object in O:\home\seri.ru\www\mail.php on line 33
Notice: Trying to get property of non-object in O:\home\seri.ru\www\mail.php on line 31

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dimonchik, 2018-10-14
@dimonchik2013

foreach ($lines as $key => $value)
print after that

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question