I want to pull the product name at this site: https://shopee.com.my/search?keyword=h370m I've received support of @DebanjanB at this question Selenium can not scrape Shopee e-commerce site using python but I am not able to apply the xpath of product name into that solution. Here is my code:
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
options = webdriver.ChromeOptions()
options.add_argument('--headless')
options.add_argument('start-maximized')
options.add_argument('disable-infobars')
options.add_argument('--disable-extensions')
browserdriver = webdriver.Chrome(chrome_options=options, executable_path=r'C:\Users\\admin\\Desktop\\chromedriver_win32\\Chromedriver')
browserdriver.get('https://shopee.com.my/search?keyword=h370m')
WebDriverWait(browserdriver, 20).until(EC.element_to_be_clickable((By.XPATH, "//div[@class='shopee-modal__container']//button[text()='English']"))).click()
print([my_element.text for my_element in WebDriverWait(browserdriver, 20).until(EC.visibility_of_all_elements_located((By.XPATH, ".//*[@class='_1JAmkB']")))])
print("Program Ended")
Also, I tried different xpath, such as:
By.XPATH, ".//*[@class='_1JAmkB']/child::div"
or
//div[contains(concat(' ', normalize-space(@class), ' '), ' _1NoI8_ ')]
Neither of them can give me the result as expected
The output I received was just:
['', '', '', '', '', '', '', '', '', '', '', '', '', '', ''] Program Ended
Please help me to solve this problem. Thanks!