I’m practicing web scraping using Selenium, and I hope to get the color of this dress. When I inspect the website, I can see the text content under the ‘screen-reader-text’ class but when I try to fetch it, I always get an empty value. What’s going on? Is it because the Zara website blocks me to scrape it? My code is the following,
driver_path = 'D:/Python/Selenium/chromedriver'
option1 = webdriver.ChromeOptions()
option1.add_experimental_option('detach',True)
driver = webdriver.Chrome(chrome_options=option1,executable_path=driver_path)
driver.get(url)
color = driver.find_element_by_xpath('//*[@id="main"]/article/div[1]/div[2]/div[1]/div[3]/ul/li[1]/button/span/span/span').text
Since I wish to get all the possible colors, I also tried the following code, which doesn’t work as well:(
colors = driver.find_elements_by_xpath('//*[@id="main"]/article/div[1]/div[2]/div[1]/div[3]/ul')
col = []
for i,color in enumerate(colors):
prefix = '//*[@id="main"]/article/div[1]/div[2]/div[1]/div[3]/ul'
try:
col.append(color.find_elements_by_xpath(prefix+f'/li[{i}]'+'/button/span/span/span').text)
except:
pass
col