0

I want to get all the item name and price from this website

For example, i want to search for "apple" https://redmart.com/search/apple

I use Goutte for scraping the website. This is the code so far to get all item's name in the list:

$client = new Client();

$crawler = $client->request('GET', 'https://redmart.com/search/apple');

$crawler->filter('h4 > a')->each(function ($node) {
    print $node->text()."\n";
});

but when i run the code, it prints nothing. How to get all the item's name and price from the list?

Krisnadi
  • 641
  • 1
  • 10
  • 23
  • 1
    Look at the source code of the page. As Binar said they are using react js and you can't parse html since there is nothing in it – Baptiste May 07 '18 at 14:51

2 Answers2

1

The redmart.com website is using react js to generate the content. You cannot use a website scraper like Goutte. Instead, try using the developer console in Firefox or Google Chrome and see what's going on.

In this case, a url is requested (via ajax) that returns JSON format and is rendered by react: https://api.redmart.com/v1.6.0/catalog/search?q=apple&pageSize=18&sort=1024&variation=BETA

With PHP, you just use json_decode on the response and you have everything you need.

Binar Web
  • 867
  • 1
  • 11
  • 26
1

Not need to scrap the web, you can just request on website rest API and use the poutput JSON, for example this is API for apple listing:

https://api.redmart.com/v1.6.0/catalog/search?q=apple&pageSize=18&sort=1024&page=1&variation=BETA

Araz Jafaripur
  • 927
  • 2
  • 12
  • 32