/    Sign up×
Community /Pin to ProfileBookmark

Web Scraper Outputs Just One Item Instead of Many

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>&nbsp;<a href=”https://www.wonatrading.com/login”>Login for Price</a>&nbsp;&nbsp;</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:UsersMaureenDesktopscraper>node scraper.js
images/20200312/thumb/AK0015-@GD-NMLT2@02H-9_3L@479684@225@[email protected]

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@makamo66authorMar 18.2020 — This problem was solved at https://www.freecodecamp.org/forum/t/web-scraper-outputs-just-one-item-instead-of-many/360427/3
Copy linkTweet thisAlerts:
@VITSUSAMar 19.2020 — Sounds good :)
×

Success!

Help @makamo66 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.7,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...