i am new to php
i am trying to make simple script to scrape product name and price
i am using html dom parser
there are 2 issues that it gives error
Warning: file_get_contents(https://eg.iherb.com/pr/california-gold-nutrition-sport-whey-protein-isolate-1-lb-16-oz-454-g/71031): Failed to open stream: HTTP request failed! HTTP/1.1 403 Forbidden in C:\xampp\htdocs\demo\simple_html_dom.php on line 1556
Fatal error: Uncaught Error: Call to a member function find() on null in C:\xampp\htdocs\demo\simple_html_dom.php:1582 Stack trace: #0 C:\xampp\htdocs\demo\index.php(15): simple_html_dom->find('a') #1 {main} thrown in C:\xampp\htdocs\demo\simple_html_dom.php on line 1582
the script couldn't open the links of the products and also i couldnot implement the 2 elements to find them and then echo them
please help me :)
here it is the code
include_once("simple_html_dom.php");
// set target url to crawl
$url = 'https://eg.iherb.com/pr/california-gold-nutrition-sport-whey-protein-isolate-1-lb-16-oz-454-g/71031'; // change this
// open the web page
$html = new simple_html_dom();
$html->load_file($url);
foreach($html->find("price-inner-text") as $price);
foreach($html->find("h1#name") as $productname);
?>
