Python 使用selenium进入Amazon的下一页
我一直在想,当我在亚马逊列表的最后一页时,我是如何看到的。我试图在没有任何效果的情况下获取屏幕底部的最后一个页码,因此我尝试了另一种方法。查看是否仍可以单击“下一步”按钮。这是我到目前为止所知道的,关于为什么它不会进入下一页有什么想法吗Python 使用selenium进入Amazon的下一页,python,selenium,google-chrome,Python,Selenium,Google Chrome,我一直在想,当我在亚马逊列表的最后一页时,我是如何看到的。我试图在没有任何效果的情况下获取屏幕底部的最后一个页码,因此我尝试了另一种方法。查看是否仍可以单击“下一步”按钮。这是我到目前为止所知道的,关于为什么它不会进入下一页有什么想法吗 from selenium.webdriver.chrome.webdriver import WebDriver from selenium import webdriver import time def next(): giveawayPage
from selenium.webdriver.chrome.webdriver import WebDriver
from selenium import webdriver
import time
def next():
giveawayPage = 1
currentPageURL = 'https://www.amazon.com/ga/giveaways?pageId=' + str(giveawayPage)
while True:
try:
nextButton = driver.find_element_by_xpath('//*[@id="giveawayListingPagination"]/ul/li[7]')
except:
nextPageStatus = 'false'
print('false')
else:
nextpageStatus = 'true'
giveawayPage = giveawayPage + 1
driver.get(currentPageURL)
if (nextPageStatus == 'false'):
break
if __name__ == '__main__':
driver = webdriver.Chrome('./chromedriver')
driver.get('https://www.amazon.com/ga/giveaways?pageId=1')
next()
这不起作用的原因是,如果你转到亚马逊赠品的最后一页,你选择的元素仍然在那里,只是不可点击。在大多数页面上,元素看起来像:
<li class="a-last">...</li>
在最后一页上,它看起来像:
<li class="a-disabled a-last">...</li>
因此,与其检查该元素是否存在,不如检查该元素是否具有“a-disabled”类。下一页的li按钮始终存在,有几种方法可以检查它是否位于最后一页:
检查li是否有多个等级,或者不仅有a级,而且还有a级禁用
检查li中是否存在该元素
你提到了亚马逊的下一页,以及当我在亚马逊列表的最后一页时我是如何看到的。你的具体用例是什么?你想做什么?我只想滚动浏览所有的列表页面,直到到达最后一页。
//li[@class="a-last"]
//*[@id="giveawayListingPagination"]/ul/li[7]/a