|
|
|
|
@@ -43,8 +43,8 @@ class CountryCompareController extends Controller
|
|
|
|
|
{
|
|
|
|
|
$requests = Http::pool(fn (Pool $pool) => [
|
|
|
|
|
$this->countries->each(function ($country) use ($pool, $ta_code) {
|
|
|
|
|
Log::info('Getting page {url}', [ 'url' => $country->search_url . $ta_code ] );
|
|
|
|
|
return $pool->as($country->country_code)->get($country->search_url . $ta_code);
|
|
|
|
|
Log::info('Getting page {url}', [ 'url' => $country->search_url . $ta_code[0] ] );
|
|
|
|
|
return $pool->as($country->country_code)->get($country->search_url . $ta_code[0] );
|
|
|
|
|
})
|
|
|
|
|
]);
|
|
|
|
|
return $requests;
|
|
|
|
|
@@ -68,7 +68,9 @@ class CountryCompareController extends Controller
|
|
|
|
|
|
|
|
|
|
if ($responses[$country] instanceof \Illuminate\Http\Client\Response && $responses[$country]->ok()) {
|
|
|
|
|
|
|
|
|
|
$response = $responses[$country]->body();
|
|
|
|
|
// dd($responses);
|
|
|
|
|
$response = (string) $responses[$country]->body();
|
|
|
|
|
//dd($response)
|
|
|
|
|
switch ($country) {
|
|
|
|
|
case "BG":
|
|
|
|
|
case "BY":
|
|
|
|
|
@@ -76,7 +78,7 @@ class CountryCompareController extends Controller
|
|
|
|
|
$prices[$country] = $this->parseJson_CY_GR_BG($code, (string) $response, $country);
|
|
|
|
|
break;
|
|
|
|
|
case "IS":
|
|
|
|
|
$prices[$country] = $this->parseJson_IS($code, (string) $response, $country);
|
|
|
|
|
$prices[$country] = $this->parseJson_IS($code,(string) $response, $country);
|
|
|
|
|
break;
|
|
|
|
|
case "TR":
|
|
|
|
|
$prices[$country] = $this->parseJson_TR((string) $response, $country);
|
|
|
|
|
@@ -104,7 +106,6 @@ class CountryCompareController extends Controller
|
|
|
|
|
|
|
|
|
|
public function parseJson($json_raw, $country)
|
|
|
|
|
{
|
|
|
|
|
try {
|
|
|
|
|
$json_values = array();
|
|
|
|
|
|
|
|
|
|
$json_decoded = json_decode($json_raw, true);
|
|
|
|
|
@@ -128,9 +129,6 @@ class CountryCompareController extends Controller
|
|
|
|
|
);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
|
return [];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $json_values;
|
|
|
|
|
}
|
|
|
|
|
@@ -165,29 +163,28 @@ class CountryCompareController extends Controller
|
|
|
|
|
public function parseJson_CY_GR_BG($code, $body , $country)
|
|
|
|
|
{
|
|
|
|
|
//echo "country: " . $country . ", code: " . $code . "<br>";
|
|
|
|
|
//Log::info('{country},{body},{code}',[$country, $body, $code]);
|
|
|
|
|
$body = file_get_contents("https://www.ikea.bg/search-results/?query=80366284");
|
|
|
|
|
|
|
|
|
|
$dochtml = new \DOMDocument();
|
|
|
|
|
@$dochtml->loadHTML('<?xml encoding="UTF-8">' . $body);
|
|
|
|
|
$dochtml->loadHTML($body);
|
|
|
|
|
|
|
|
|
|
$xpath = new \DOMXpath($dochtml);
|
|
|
|
|
$price = null;
|
|
|
|
|
$c = ltrim($code, "0");
|
|
|
|
|
$json_values = array();
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
$price = $xpath->query('//*/div[(@class="yotpo yotpo-main-widget" and @data-product-id="' . $code . '")]/@data-price')[0]->nodeValue;
|
|
|
|
|
$url_product = $xpath->query('//*/div[(@class="yotpo yotpo-main-widget" and @data-product-id="' . $code . '")]/@data-url')[0]->nodeValue;
|
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
|
return [];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$price = floatval($price);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$json_values = array(
|
|
|
|
|
'url' => $url_product,
|
|
|
|
|
'url_product' => $url_product,
|
|
|
|
|
'tag' => null,
|
|
|
|
|
'price' => floatval($price),
|
|
|
|
|
'country' => $country,
|
|
|
|
|
'price_eur' => 0
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
return $json_values;
|
|
|
|
|
@@ -205,7 +202,6 @@ class CountryCompareController extends Controller
|
|
|
|
|
$c = ltrim($code, "0");
|
|
|
|
|
$json_values = array();
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
$price = $xpath->query('//*/div[(@class="itemPriceBox" and @data-item="' . $c . '")]//p[@class="itemNormalPrice display-6"]/span')[0]->nodeValue;
|
|
|
|
|
|
|
|
|
|
if (is_null($price) || empty($price)) {
|
|
|
|
|
@@ -225,9 +221,6 @@ class CountryCompareController extends Controller
|
|
|
|
|
default:
|
|
|
|
|
$url_product = null;
|
|
|
|
|
}
|
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
|
return [];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (is_null($price) || empty($price)) {
|
|
|
|
|
$url_product = null;
|
|
|
|
|
@@ -249,6 +242,10 @@ class CountryCompareController extends Controller
|
|
|
|
|
{
|
|
|
|
|
//echo "country: " . $country . ", code: " . $code . "<br>";
|
|
|
|
|
|
|
|
|
|
//$body = file_get_contents("https://ikea.is/is/search/?q=80366284");
|
|
|
|
|
// $client = new \GuzzleHttp\Client();
|
|
|
|
|
// $res = $client->request('GET', 'https://ikea.is/is/search/?q=80366284');
|
|
|
|
|
// $body= $res->getBody()->getContents();
|
|
|
|
|
$dochtml = new \DOMDocument();
|
|
|
|
|
@$dochtml->loadHTML('<?xml encoding="UTF-8">' . $body);
|
|
|
|
|
|
|
|
|
|
@@ -280,7 +277,7 @@ class CountryCompareController extends Controller
|
|
|
|
|
$json_values = array(
|
|
|
|
|
'url' => $url_product,
|
|
|
|
|
'tag' => null,
|
|
|
|
|
'price' => $price,
|
|
|
|
|
'salesPrice' => $price,
|
|
|
|
|
'country' => $country,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|