I got the next url related to an online store https://www.tiendasjumbo.co/buscar?q=mani and I can't extract the product label an another fields:
from selenium import webdriver
import time
from random import randint
driver = webdriver.Firefox(executable_path= "C:\Program Files (x86)\geckodriver.exe")
driver.implicitly_wait(10)
time.sleep(4)
url = "https://www.tiendasjumbo.co/buscar?q=mani"
driver.maximize_window()
driver.get(url)
driver.find_element_by_xpath('//h1[@class="impulse-title"]')
What am I doing wrong, I also tried to switch the iframes but there is no way to achieve my goal? any help is welcome.
The Excel MID function extracts a given number of characters from the middle of a supplied text string. For example, =MID("apple",2,3) returns "ppl". The Excel LEN function returns the length of a given text string as the number of characters.
Depending on where you want to start extraction, use one of these formulas: LEFT function - to extract a substring from the left. RIGHT function - to extract text from the right. MID function - to extract a substring from the middle of a text string, starting at the point you specify.
The easiest way to extract a substring between two delimiters is to use the text to column feature in Excel, especially if you have multiple delimiters. In this example, use =MID(A2, SEARCH(“-“,A2) + 1, SEARCH(“-“,A2,SEARCH(“-“,A2)+1) – SEARCH(“-“,A2) – 1) in cell B2 and drag it to the entire data range.
The products within the website https://www.tiendasjumbo.co/buscar?q=mani are located within a #shadow-root (open)
.
To extract the product label you have to use shadowRoot.querySelector()
and you can use the following Locator Strategy:
Code Block:
driver.get('https://www.tiendasjumbo.co/buscar?q=mani')
item = driver.execute_script("return document.querySelector('impulse-search').shadowRoot.querySelector('div.group-name-brand h1.impulse-title span.formatted-text')")
print(item.text)
Console Output:
La especial mezcla de nueces, maní, almendras y marañones x 450 g
You can find a couple of relevant discussions in:
Chrome v96 has changed the shadow root return values for Selenium. Some helpful links:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With