2021年1月21日星期四

Selenium 'list' object has no attribute 'text'

So I'm using python and selenium to scrape the product titles on a sephora page.

url = 'https://www.sephora.com/ca/en/shop/face-makeup'    driver.get(url)    time.sleep(2)       browser = scrollDown(driver, 20)    # this selected the div for every product on the page  products = driver.find_elements_by_class_name('css-79elbk')    for product in products:      title = product.find_elements_by_xpath('/html/body/div[1]/div[2]/div/div/div/div[2]/div[1]/main/div[3]/div/div[1]/div[1]/div[1]/a/div/div[4]/span[2]').text      print(title)  

The problem is that when I run it I get Line 48: AttributeError: 'list' object has no attribute 'text'. The title is in a span that is nested in a div. I've tried this on a normal div with text inside and it scrapes it no problem.

https://stackoverflow.com/questions/65838195/selenium-list-object-has-no-attribute-text January 22, 2021 at 09:36AM

没有评论:

发表评论