@@ -127,12 +127,13 @@ Now, since we're able to use jQuery, let's translate our vanilla JavaScript code
127127await page .addScriptTag ({ url: ' https://code.jquery.com/jquery-3.6.0.min.js' });
128128
129129const products = await page .evaluate (() => {
130- return Array .from ($ (' .product-item' ).map (function () {
130+ const productCards = $ (' .product-item' );
131+ return productCards .map (function () {
131132 const card = $ (this );
132133 const name = card .find (' .product-item__title' ).text ();
133134 const price = card .find (' .price' ).contents ().last ().text ();
134135 return { name, price };
135- }));
136+ }). get ( );
136137});
137138
138139console .log (products);
@@ -216,12 +217,13 @@ Now, to loop through all of the products, we'll make use of the `$` object and l
216217``` js
217218const $ = load (await page .content ());
218219
219- const products = Array .from ($ (' .product-item' ).map (function () {
220+ const productCards = $ (' .product-item' );
221+ const products = productCards .map (function () {
220222 const card = $ (this );
221223 const name = card .find (' .product-item__title' ).text ();
222224 const price = card .find (' .price' ).contents ().last ().text ();
223225 return { name, price };
224- }));
226+ }). get ( );
225227
226228console .log (products);
227229```
@@ -244,12 +246,13 @@ await page.goto('https://warehouse-theme-metal.myshopify.com/collections/sales')
244246
245247const $ = load (await page .content ());
246248
247- const products = Array .from ($ (' .product-item' ).map (function () {
249+ const productCards = $ (' .product-item' );
250+ const products = productCards .map (function () {
248251 const card = $ (this );
249252 const name = card .find (' .product-item__title' ).text ();
250253 const price = card .find (' .price' ).contents ().last ().text ();
251254 return { name, price };
252- }));
255+ }). get ( );
253256
254257console .log (products);
255258
@@ -270,12 +273,13 @@ await page.goto('https://warehouse-theme-metal.myshopify.com/collections/sales')
270273
271274const $ = load (await page .content ());
272275
273- const products = Array .from ($ (' .product-item' ).map (function () {
276+ const productCards = $ (' .product-item' );
277+ const products = productCards .map (function () {
274278 const card = $ (this );
275279 const name = card .find (' .product-item__title' ).text ();
276280 const price = card .find (' .price' ).contents ().last ().text ();
277281 return { name, price };
278- }));
282+ }). get ( );
279283
280284console .log (products);
281285
0 commit comments