Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I'm trying to fetch a product name and price on this website Toplivo.bg

I am using the Simple HTML DOM parser to get it. Here is my code

include_once('simple_html_dom.php');

$link="https://toplivo.bg/en/products/Construction-materials/Dry-construction-mixtures/Screeds-and-flooring";

$html = file_get_html($link);
//Price
foreach ($html->find('div[class="content"]') as $text){
  echo $text -> plaintext.'<br>';
}
?> 

The problem is that first, I need to select the warehouse on the website to get the price for "Baumit Cement screed Baumit Solido E160, 25 kg".

Can I select it by default through PHP code? For example, I want to select the "Plovdiv region -> Plovdiv Store"

Thanks for helping!

question from:https://stackoverflow.com/questions/66058381/how-to-pass-store-selection-in-simple-html-dom-parser

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
143 views
Welcome To Ask or Share your Answers For Others

1 Answer

This can be achieved using cURL. Complete code below:

<?php
include_once('simple_html_dom.php');

$link = "https://toplivo.bg/en/products/Construction-materials/Dry-construction-mixtures/Screeds-and-flooring";

// let's use curl to create a get request first to select a store while keeping the session using a cookie file
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://toplivo.bg/izborNaSklad/39');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookie-45fg.txt');
curl_setopt($ch, CURLOPT_COOKIEFILE, 'cookie-45fg.txt');
$output = curl_exec($ch);

curl_setopt($ch, CURLOPT_URL, $link); // now let's fetch the raw content of the store products page
$output = curl_exec($ch);

$html = str_get_html($output); // since we have the raw input, we can use the str_get_html method instead of file_get_html

//Price
foreach ($html->find('div[class="content"]') as $text){
  echo $text->plaintext . '<br>';
}

?>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share

548k questions

547k answers

4 comments

86.3k users

...