1

I downloaded the Simple Html DOM library files, and using this piece of code on top of my .php file I managed to call the simple_html_dom file ( note that I am running this on a server thus I used the built in php function getcwd() to call the directory of the project's folder ).

CODE:

<?php
$hard_path = getcwd().'/';
require_once "$hard_path".'simple_html_dom.php';

Moving on I am interested in returning or echoing the html content of this URL, https://www.skroutz.gr/s/36232462/Asus-TUF-Dash-F15-FX516PC-HN004W-15-6-FHD-144Hz-i7-11370H-16GB-512GB-SSD-GeForce-RTX-3050-W11-Home-US-Keyboard.html?from=home_price_drops.

PROBLEM:

To simply echo the html content of the url, I used the Simple HTML DOM's library function called file_get_html(). But when I use the code below to echo the content of the page I get no output( note that this happens only with skroutz.gr wepsite links and incase I use a different link for example from wikipedia or any other site in general I do get content in the output of my .php file ). Also there are no errors being returned.

code:

$dom = file_get_html('https://www.skroutz.gr/s/36232462/Asus-TUF-Dash-F15-FX516PC-HN004W-15-6-FHD-144Hz-i7-11370H-16GB-512GB-SSD-GeForce-RTX-3050-W11-Home-US-Keyboard.html?from=home_price_drops');
echo $dom;

COMPLETE CODE:

<?php
$hard_path = getcwd().'/';
require_once "$hard_path".'simple_html_dom.php';

$dom = file_get_html('https://www.skroutz.gr/s/36232462/Asus-TUF-Dash-F15-FX516PC-HN004W-15-6-FHD-144Hz-i7-11370H-16GB-512GB-SSD-GeForce-RTX-3050-W11-Home-US-Keyboard.html?from=home_price_drops');
echo $dom;

QUESTIONS:

  • Why am I not getting any output when I try to read skroutz.gr's weblinks?
  • Are there any mistakes in my code that I should be aware of?

Thanks in advance for your time and effort!

  • 1
    _"Why am I not getting any output when I try to read skroutz.gr's weblinks?"_ - probably because that site does not want you to rip their content in such ways, and has implemented measures against it. Sending a User-Agent mimicking a current browser is one of the simpler things that can sometimes help, but it really depends on the specific site. – CBroe Jul 15 '22 at 07:25
  • Hello @CBroe , Thanks for the advice, could you provide a link about the `Sending a User-Agent mimicking a current browser`? – Periklis Kakarakidis Jul 15 '22 at 07:29
  • 1
    You can do that via the `context` parameter. https://stackoverflow.com/questions/2107759/php-file-get-contents-and-setting-request-headers – CBroe Jul 15 '22 at 07:31

0 Answers0