0

I'm trying to use JavaScript to scrape data from the following page, specifically the "free shipping free returns" text that appears when you hover your mouse over the cart icon:

enter image description here

Whenever I hover over the cart icon, new HTML is added to the DOM.

enter image description here

And when I move my mouse away, the the previously added HTML goes away. I want to be able to parse data from the HTML that gets added without having the popup visible. How would I be able to scrape this text data even if someone does not hover over the cart icon? Is there a way to access all the HTML data at once?

2 Answers2

0

You can try to catch the JavaScript function being executed when you hover your mouse over the cart icon. You can do this via the developer tools. Add break points to code execution if the DOM changes (on the parent element in which the new element is added).

Once you get the function, just execute it directly on that page and you'll probably be able to see the popup and extract it's contents.

You could also try to simulate a hover as explained in these answers: How do I simulate a mouseover in pure JavaScript that activates the CSS ":hover"?

nvkrj
  • 1,002
  • 1
  • 7
  • 17
0

Scraping a page for data is not usually recommended since they can change over time (especially ones not written directly in HTML, but are rather generated (usually they have CSS classes like 8h2H1)). If this is not supposed to be a long-term solution, the above answer by @nvkrjn is a good answer. Or, you can just check for an element with the id name free-shipping-label. free shipping screenshot on nordstrom But, if this is supposed to be a long-term solution, then I would suggest using an API (this site doesn't seem to have one) or querying the database like how to Javascript does. Also, if you're using a non-browser environment (eg BeautifulSoup), it may not run the JS required to get the data.

Ken Shibata
  • 71
  • 1
  • 9