Good day.
There is a function for parsing the site. The html_simple_dom_parser library is html_simple_dom_parser . I can parse the information I need about a single object, but I don’t understand how to loop a function so that I can transmit, for example, an array of references, and I was given a table with many objects.
Function code:
<?php header('Content-Type: text/html; charset=UTF-8'); mb_internal_encoding('UTF-8'); mb_http_output('UTF-8'); mb_http_input('UTF-8'); mb_regex_encoding('UTF-8'); ini_set('display_errors', 'Off'); # подключаем библиотеку include('../simple_html_dom.php'); # глобальный массив, который будет заполняться информацией статьи $articles = array(); $URL = '____________________'; function getArticles($page) { global $urls, $articles, $descriptions; $html = new simple_html_dom(); $html->load_file($page); $items = $html->find('div[class=column]'); foreach($items as $post) { # выбираем и записываем в массив данные для парсинга $articles[] = array(price => $post->children(0)->children(1)->children(2)->outertext); $articles[] = array(price => $post->children(3)->children(1)->children(1)->outertext); $articles[] = array(price => $post->children(3)->children(1)->children(2)->outertext); $articles[] = array(price => $post->children(3)->children(1)->children(3)->outertext); $articles[] = array(price => $post->children(3)->children(1)->children(4)->outertext); $articles[] = array(price => $post->children(3)->children(1)->children(5)->outertext); $articles[] = array(price => $post->children(3)->children(1)->children(6)->outertext); $articles[] = array(price => $post->children(3)->children(1)->children(7)->outertext); $articles[] = array(price => $post->children(3)->children(1)->children(8)->outertext); $articles[] = array(price => $post->children(3)->children(1)->children(9)->outertext); $articles[] = array(price => $post->children(3)->children(2)->outertext); $articles[] = array(price => $post->children(3)->children(0)->find('a', 1)->outertext); } } ?> Call the function and draw the table:
<?php getArticles($URL); $table = "<table border=1 class='table'><tbody><tr>"; #See here the start of the first row foreach($articles as $a => $item) { $table .= "<td>$item[price]</td>"; #double quotes for the variables if(($a+1) % 12 == 0) $table .= "</tr><tr>"; } $table .= "</tr></tbody></table>"; #end the row #append the text and don't overwrite it at the end echo $table; ?> Parsing result
Thanks in advance for your help.
