Answer the question
In order to leave comments, you need to log in
Maybe someone has an example of the implementation of the parser from avito to php?
I want to parse ads from avito to PHP, maybe there is some or a simple code?
So far I have only found something similar: https://habrahabr.ru/sandbox/110358/ , https://github.com/europaoceans/avito_parser_php/b...
Answer the question
In order to leave comments, you need to log in
Maybe someone will need it!
Used the nokogiri library ( - nokogiri - )
<?php
header('Content-Type: text/html; charset=utf-8');
include("nokogiri.php");
$html = file_get_contents('https://m.avito.ru/ГОРОД/avtomobili/');
$saw = new nokogiri($html);
print "<pre>";
foreach ($saw->get('article.b-item') as $item){
$adv = new stdclass;
$adv->id = $item['data-item-id'];
$adv->url = $item['div'][0]['a'][0]['href'];
if($item_image = $item['div'][0]['a'][0]['div'][0]['span'][0]['style']){
$adv->image_thumbnail = preg_replace('~.+url\((.+)\).+~', '$1', $item_image);
$adv->image_original = str_replace('140x105', '640x480', $adv->image_thumbnail);
}
$adv->price = $item['div'][0]['a'][0]['div'][1]['span'][0]['#text'][0];
$adv->price_normal = preg_replace('/[^0-9]+/', '', $adv->price);
$adv->date = trim($item['div'][0]['a'][0]['div'][2]['div'][0]['#text'][0]);
print_r($adv);
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question