I am currently working on a project that scrapes content from a dynamically generated page and records it.
The below is an example of the structure I am pulling from.
https://dutchie.com/embedded-menu/revolutionary-clinics-somerville/menu
I am able to scroll down the page and locate the specific details from each product card, using:
cards = driver.find_elements_by_css_selector("div[class^='product-card__Content']")
From each card, I am able to pull the title, price and other variables and store them as needed.
The problem is that I want to append to these the "category" which happens to appear as a header above each grouping of items, example from above being flower followed by prerolls. As the page scrolls down a new one of these is displayed followed by the related item.
I have been able to access the first instance of this, but no matter where I put the following code in my loop it never pulls the updated value, only the initial.
category = driver.find_element_by_css_selector("div[class^='products-grid__ProductGroupTitle']").text
I tried to figure a way to pull this as the parent/ancestor of the current card, but this concept is still new to me and outside my understanding of how I would solve it. Is locating the "nearest" ProductGroup title the correct approach? If so how would I do so dynamically as the page scrolls?
Thanks!