Web Scraper Outputs Just One Item Instead of Many

javascript , node , scraping United States
  • 11 months ago

    A part of my view source looks like this:

    <td align="center" valign="top" class="productListing-data" style="position:relative;padding-bottom: 5px;" width="25%">
    <a style="position:relative;float:left;" href="product_info.php?products_id=474302&kind=2&cPath=172_93_96&description=
    3PCS---Round-Metal-Link-Chain-Layered-Anklets-">
    <img src="images/20200131/thumb/AK0065-@GDXX@3P-03H-75_3L@474302@350@[email protected]" title="
    3PCS - Round Metal Link Chain Layered Anklets " width="200" border="0" height="200" alt="
    3PCS - Round Metal Link Chain Layered Anklets ">
    <td align="center" valign="top" class="productListing-data" style="position:relative;padding-bottom: 5px;" width="25%">
    <a style="position:relative;float:left;" href="product_info.php?products_id=474303&kind=2&cPath=172_93_96&description=
    3PCS---Round-Metal-Link-Chain-Layered-Anklets-">
    <img src="images/20200131/thumb/AK0065-@RHXX@3P-03H-75_3L@474303@350@[email protected]" title="
    3PCS - Round Metal Link Chain Layered Anklets " width="200" border="0" height="200" alt="
    3PCS - Round Metal Link Chain Layered Anklets ">
    <td align="center" valign="top" class="productListing-data" style="position:relative;padding-bottom: 5px;" width="25%">
    <a style="position:relative;float:left;" href="product_info.php?products_id=479684&kind=2&cPath=172_93_96&description=Faceted-Bead-Pearl-Link-Anklet">
    <img src="images/20200312/thumb/AK0015-@GD-NMLT2@02H-9_3L@479684@225@[email protected]" title="Faceted Bead Pearl Link Anklet" width="200" border="0" height="200" alt="Faceted Bead Pearl Link Anklet"><span class="small_cart" ></span></a><a href="product_info.php?products_id=479684&kind=2&cPath=172_93_96&description=Faceted-Bead-Pearl-Link-Anklet"><span style="display:-webkit-inline-box">479684</span><br /><a href="product_info.php?products_id=479684&kind=2&cPath=172_93_96&description=Faceted-Bead-Pearl-Link-Anklet"><font style="display: block;height:40px;text-transform: uppercase;" title="Faceted Bead Pearl Link Anklet">Faceted Bead Pearl Link Anklet</font></a> <a href="https://www.wonatrading.com/login">Login for Price</a>  </td>
    

    My node code looks like this: const rp = require('request-promise'); const $ = require('cheerio'); const url = 'https://www.example.com';

    rp(url)
    .then(function(html) {
    console.log($('td.productListing-data > a > img', html).attr('src'));
    })
    .catch(function(err) {
    //handle error
    });
    

    When I execute the file, I get just one image when I should get all three: C:\Users\Maureen\Desktop\scraper>node scraper.js images/20200312/thumb/AK0015-@GD-NMLT2@02H-9_3L@479684@225@[email protected]

  • 11 months ago

    This problem was solved at https://www.freecodecamp.org/forum/t/web-scraper-outputs-just-one-item-instead-of-many/360427/3

Post a reply

Enter your message below

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“To iterate is human, to recurse divine” - L. Peter Deutsch