N
N
Nikolay2016-08-17 23:12:03
PHP
Nikolay, 2016-08-17 23:12:03

How to download second level pages of simple_html_dom.php?

Tell me how to download second-level pages from the catalog links using simple_html_dom.php
I took all the links to the flights:

// set_time_limit(10);
require_once 'simple_html_dom.php';
require_once 'curl.php';
$site = 'http://biletyczarterowe.r.pl';
$html = curl_get('http://biletyczarterowe.r.pl');
$dom = str_get_html($html);

foreach($dom->find('table[id=prawyKwadrat] tr td a') as $element) {
    $a = $element->href;
   		$a = $site . htmlspecialchars_decode($a);
// --------------------------------------------------------------
   		$page = curl_get($a);
   		$page_dom = str_get_html($page);
    file_put_contents(md5($page_dom) . '.html', $page_dom);
  }

And how now to parse these very links and how to create pages on them?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
D
Decadal, 2016-08-17
@Decadal

//в теле цикла
$linkPage = file_get_html($element->href);
// и лучше сделать рекурсивно - оформить парсинг страниц как функцию, принимающую html и кинуть этот контент в неё же 
//а это для решения вашей задачи
file_put_contents(<хэш имени файла>, $linkPage);

if you need to parse not only the page, but everything that the target page links to, then it is better to use cURL. At least if the nesting level is more than two.

A
amorphine, 2016-08-17
@amorphine

updated

$html = file_get_html('http://biletyczarterowe.r.pl/');
foreach($html->find('table[id] tr td a') as $element) {
    $outer_html  = file_get_html($element->href);
    $file = fopen(md5($outer_html) . '.html', 'w');
    fwrite($file, $html);
    fclose($file);
}

N
Nikolay, 2016-08-18
@zzzmaikzzz

None of the options worked...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question