Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ArseniyShestakov/bdd6ca7436ecc2c99b102ae723c36453 to your computer and use it in GitHub Desktop.
Save ArseniyShestakov/bdd6ca7436ecc2c99b102ae723c36453 to your computer and use it in GitHub Desktop.
Just random website price parser
<?php
define('TAB', ' ');
$pizz = array(
"30cm" => "http://www.pizzmaster.ru/shop/pizza-30sm",
"40cm" => "http://www.pizzmaster.ru/shop/pizza-40sm",
"12" => "http://www.pizzmaster.ru/shop/polovinka-pizz",
"to" => "http://www.pizzmaster.ru/shop/picca-40sm-na-tonkom-korzhe",
"it" => "http://www.pizzmaster.ru/shop/picca-40sm-na-italjanskom-teste"
);
$result = array();
foreach($pizz as $type => $url)
{
$content = file_get_contents($url);
preg_match_all('~<table><tbody><tr>(.+)</li><font><font>~isU', $content, $matches);
foreach($matches[1] as $item)
{
preg_match('~.+<a href="[^"]+">([^<]+)</a></font>.+price">([0-9\.^]+)руб</span>.+art"><font><font>([0-9\.]+)</font>~isU', $item, $m2);
preg_match('~"([^"]+)"~', $m2[1], $title);
$result[$title[1]][$type] = array(
'price' => $m2[2],
'weight' => $m2[3],
);
}
}
foreach($result as $name => $data)
{
echo $name. TAB;
foreach($data as $type => $data2)
{
echo $data2['price']. '('. $data2['weight']. ')' . TAB;
}
echo PHP_EOL;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment