I'm struggling to wrap my head around what is actually returned when we scrape a parent element with JS/jQuery. Through my learning, I have found that a good way to approach scraping an item on the page with multiple properties that we want scrape into unique arrays (let's say Book Title, Book Price, Inventory Status), would be to locate the parent element, convert that an array, then .map()
through it to extract each element that we want.
For a simple example, all of the data I need is located in the product_pod
class in the code below.
<article class="product_pod">
<div class="image_container">...</div>
<p class="star-rating Five">...</p>
<h3>
<a href="catalogue/libertarianism_for_beginners_999/index.html" title="Libertarianism for Beginners">Libertarianism for Beginners</a>
</h3>
<div class="product_price">
<p class="price_color">$53.74</p>
<p class="instock">In Stock</p>
</div>
</article>
So I understand that I need to iterate through the product_pod
array. I've followed other programmer's leads to come up with this:
const container = $('.product_pod').toArray();
let mapper = container.map(elem => {
const activate = $(elem);
const title = activate.find('a').map((i, x) => $(x).attr('title'));
const price = activate.find('.price_color').text();
const inventory = activate.find('.instock').text().trim();
return({title,price,inventory});
})
Or something like that.
What I'm asking is that when I console.log(container)
, I get this absolutely unreadable object returned (img below), where Book Title, Book Price, Inventory Status are nowhere to be found.
Why does it do this? How can I read this? And how can I set up a map function with all of these unnamed [Object], [Array]
fields, when I have no idea how to iterate through the gibberish?
Thank you guys and gals.