[英]get total pages number of webpage python
我在 StackOverflow 上阅读了很多,但找不到适合我情况的任何内容。
所以,我正在尝试打开一个网站并搜索关键字。 我想在每一页上查看价格。 我将对所有页面执行此操作。
最初,我尝试单击下一步按钮,但该网站上的“下一步”按钮没有被禁用。 例如,如果有 15 页,那么在第 15 页的下一页按钮应该被禁用,但我可以无限次点击它。 在第 15 页之后,点击它,它只显示第 15 页。
所以我得到了总页数并使用 while 循环,如下所示:任何人都可以在语法上帮助我吗? 我做了以下事情:
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import WebDriverWait as wait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
#open a website and search a keyword
from selenium import webdriver
driver =webdriver.Firefox()
driver.get('https://www.insight.com/en_US/search.html')
list=['printer','printer cartridges','printer accessories']
for searchelement in list:
inputElement = driver.find_element_by_id("search-tab-banner-box-input")
inputElement.clear()
inputElement.send_keys(list)
wait( driver, 30 ).until( EC.visibility_of_element_located( (By.ID, "search-tab-banner-box-input") ) ).send_keys(Keys.ENTER )
inputElement.send_keys(Keys.TAB )
i=1
#Get total number of pages in search result and navigate through
# I want to do something like this. this is my logic not real code
totalpages= enumerate(driver.gettotalnumber of pages)
while (i<totalpages)
driver.find_element_by_class_name( "ion-chevron-right" ).click()
i+=1
#Get total number of pages
如何获得该变量中的总页数?
price='0'
while True:
if price!=driver.find_element_by_class_name("prod-price"):
driver.find_element_by_class_name( "ion-chevron-right" ).click()
else:
break
i+=1
price=driver.find_element_by_class_name("prod-price")
#Get total number of pages
print('the total number of pages is ', i)
这应该有效。 它比较页面的价格。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.