0

I am trying web Scraping using cheerio and http in node js

part of html code:

<tr>
    <td id="priceblock_saleprice_lbl" class="a-color-price a-size-base a-text-right a-nowrap">Sale:</td>

    <td class="a-span12">
    <span id="priceblock_saleprice" class="a-size-medium a-color-price"><span class="currencyINR">&nbsp;&nbsp;</span> 585.00</span>

    </td>
</tr>

nodejs code :

var sale_price = '#priceblock_saleprice';
            scraper(sale_price).filter(function(){
            var data_price = scraper(this);
            console.log(data_price.text());
            scraped = scraped + data_price.text()+';';
          });

 this code is giving 585 as output.

but in same:

part of html page:

<tr id="priceblock_ourprice_row">
    <td id="priceblock_ourprice_lbl" class="a-color-secondary a-size-base a-text-right a-nowrap">Price:</td>
    <td class="a-span12">
        <span id="priceblock_ourprice" class="a-size-medium a-color-price"><span class="currencyINR">&nbsp;&nbsp;</span> 329.00</span>
    </td>
</tr>

nodejs code:

var mrp  = '#priceblock_ourprice_lbl';
scraper(mrp).filter(function(){
            var data_mrp = scraper(this);
            console.log(data_mrp.text());
            scraped = scraped + data_mrp.text()+';';
          });

It is not giving an output.

Shubham Batra
  • 2,357
  • 5
  • 29
  • 48

2 Answers2

0

you are using wrong id... It should be priceblock_ourprice

var mrp  = '#priceblock_ourprice';
scraper(mrp).filter(function(){
   var data_mrp = scraper(this);
   console.log(data_mrp.text());
   scraped = scraped + data_mrp.text()+';';
});
Vicky Gonsalves
  • 11,593
  • 2
  • 37
  • 58
0

The id used in the 2nd code snippet is pointing to the 1st <td> element , but you need to target the 2nd <td> element, so use "#priceblock_ourprice"

Mr Lister
  • 45,515
  • 15
  • 108
  • 150
Sourab Reddy
  • 353
  • 2
  • 14