不是 return 答案并且在标题列表索引超出范围

Not return the answer and also say in title list index out of range

不是return答案还说列表索引超出标题范围

url = 'https://www.adidas.com/us/women-athletic_sneakers'
driver = webdriver.Chrome('D:/chromedriver')
driver.get(url)
time.sleep(3)
time.sleep(2)

w_shoes = driver.find_elements_by_class_name('grid-item___3rAkS')
for shoe in w_shoes:
    
title = shoe.find_elements_by_xpath('//*[@id="product-search-results"]/div[2]/div[3]/div[4]/div[1]/div/div/div[3]/div[2]/a')[0].text
print(title)
    

您为什么不尝试使用眨眼间就能为您获取所需内容的请求?

import requests

url = "https://www.adidas.com/api/plp/content-engine?"

params = {
    'sitePath': 'us',
    'query': 'women-athletic_sneakers'
}

headers = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36'
}

res = requests.get(url,params=params,headers=headers)
for item in res.json()['raw']['itemList']['items']:
    print(item['displayName'])

输出如下:

Ultraboost OG Shoes
Super Super Sleek 72 Shoes
Forum Mid Shoes
Forum Mid Shoes
Ultraboost 21 Shoes