I build a PHP scrapper that scraps a website with the URL (https://www.forebet.com/en/values); My code for finding the title is:
require 'simple_html_dom.php';
$html=file_get_html("https://www.forebet.com/en/values");
echo $html->find('title', 0)->plaintext;
It DOES work when I am running it on my computer, but it doesn't run on a server. It shows the error message"This page isn’t workingwager1x2.com is currently unable to handle this request. HTTP ERROR 500".
By enabling the 'PHP error code display function' which is ini_set('display_errors', 1); it shows a fatal error before a warning:
Warning: "file_get_contents(https://www.forebet.com/en/values): failed to open stream: HTTP request failed! HTTP/1.1 403 Forbidden in /home/winbvgmt/wager1x2.com/forbet_scrapper/simple_html_dom.php on line 84" Line 79-84 of simple_html_dom is:
$contents = file_get_contents( $url, $use_include_path, $context, $offset, $maxLen);Fatal Error: "Uncaught Error: Call to a member function find() on bool in /home/winbvgmt/wager1x2.com/forbet_scrapper/php.php:16 Stack trace: #0 {main} thrown in /home/winbvgmt/wager1x2.com/forbet_scrapper/php.php on line 16". Line 16 is:
echo $html->find('title', 0)->plaintext;
I tried checking it on google.com and it works perfectly for google.
Maybe it for security reason. There are two reason types. One is them is remote server security . Another is local server(hosting) security is blocking when you send request to remote server. Instead of this you may use curl library. For example: