Collect information from many elements with identic class (Selenium, Python) -
i trying collect name , price things in ebay. example searched "armani", need collect every item on first page using selenium , append list. have problem in code:
mylist = list() in driver.find_element_by_xpath(".//*[@id='item3aeba8d9f0']/div"): name = a.findelement(by.xpath(".//*[@id='item3aeba8d9f0']/div/div[2]/h3]")).gettext() price = a.findelement(by.xpath(".//*[@id='item3aeba8d9f0']/div/div[3]/div[2]/div/span[1]/span")).gettext() mylist.append(name, price) print(name) the result should like: [[name, price],[name, price],...]
it sounds want append tuples list of form (name, price). attempting iterate through single web element when want iterate through collection of web elements.
mylist = list() in driver.find_elements_by_xpath(".//*[@id='item3aeba8d9f0']/div"): ##change .find_elements .find_element name = a.findelement(by.xpath(".//*[@id='item3aeba8d9f0']/div/div[2]/h3]")).gettext() price = a.findelement(by.xpath(".//*[@id='item3aeba8d9f0']/div/div[3]/div[2]/div/span[1]/span")).gettext() mylist.append((name, price)) // change here!!! ##or instead of tuples 2 element list. mylist.append([name, price]) // change here!!! print(name)
Comments
Post a Comment