我的代码是:
driver.get("http://www.thegoodguys.com.au/buyonline/SearchDisplay?pageSize=16&beginIndex=0&searchSource=Q&sType=SimpleSearch&resultCatEntryType=2&showResultsPage=true&pageView=image&searchTerm=laptops")
link=();
linkPrice=();
price=();
productName=[];
Site='Harvey Norman'
link=driver.find_elements_by_class_name("photo")
linkPrice=driver.find_elements_by_class_name("product-title")
price=driver.find_elements_by_xpath("//div[@class='purchase']/span/span")
我不确定提供的 xpath 和 class_name 是否正确。有人可以验证一下它们吗?请告诉我如何找到它们
最佳答案
在 Firefox 中,您只需使用 developer tools或firebug检查 html 中的类和元素 id。继link在你的问题中,我可以找到一个名为 photo 的类,但对于 linkPrice 和 Price,你应该使用其他类。
尝试:
price=driver.find_elements_by_class_name("price")
linkPrice=driver.find_elements_by_class_name("addtocart")
这给了我:
price[0].text
u'$496'
linkPrice[0].text
u'ADD TO CART'
关于python - 如何查找元素的xpath、类名 python selenium,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24277313/