0

I'm trying to scrape the information from data-asin under the main class

<div class = "s-main-slot s-result-list s-search-results sg-row">

enter image description here

I need the data from the first six asins as: B081G75GPQ, B081FBQZ95, B084HZ7PV3, B084HZFBRZ, B087N66CJT,B07TYQ3KYX and to paste them on a row in excel.

Until now I tried this but isn't working, in there another way to access this info and copy in excel?

elements = driver.find_elements_by_class_name(
        's-main-slot s-result-list s-search-results sg-row')
    for e in elements:
        print(e.get_attribute('data-asin'))
    else:
        print('not found')
Isa
  • 145
  • 8

1 Answers1

0

See this problem with selenium and compound class selectors: https://stackoverflow.com/a/32044129/1387701

from selenium.webdriver.common.by import By
driver.findElement(By.cssSelector(".s-main-slot.s-restul-list"));

also looks like you might want to grab that element and then find the divs that live under it.

list = driver.find_element_by_css_selector(By.cssSelector(".s-main-slot.s-result-list"));
divs = list.find_elements_by_xpath("./div")
for d in div:
        print(e.get_attribute('data-asin'))
DMart
  • 2,401
  • 1
  • 14
  • 19