for products in self.br.find_elements_by_xpath("//*[@class='image']/a"):
self.urls.append(products.get_attribute("href"))
此代碼將查找所有類的hrefs鏈接。通過XPath查找元素後退
我的問題是,網頁有變化的來源有時它可以是//*[@class='image']/a
但有時//*[@class='newPrice']/a
。如果第一個xpath選項沒有找到任何東西,我怎樣才能將for
循環更改爲使用其他表達式?
完美的作品就像一個魅力! –