python selenium爬分页(上一页,1, 2, 3, 下一页)(1)

python 如何爬 分页

 

 

from selenium import webdriver
import time

phantomjs_path="C:\\Users\\XXX\\Python\\MY\\phantomjs-2.1.1-windows\\bin\\phantomjs.exe"
#driver = webdriver.PhantomJS(executable_path= phantomjs_path)

chromeOptions = webdriver.ChromeOptions()
chromeOptions.add_experimental_option('useAutomationExtension', False)

driver = webdriver.Chrome(executable_path="C:\\Users\\XXX\\Python\\MY\\webdriver-Chrome\\chromedriver.exe",options=chromeOptions )
driver.get("https://www.google.com/search?rlz=1C1GCEB_enIN826IN826&ei=MF9_XIyTGZmDoAS674_gCQ&q=chromedriver+download+&oq=chromedriver+download+&gs_l=psy-ab.3..0i20i263j0l6j0i20i263j0l2.19434.30850..31556...1.0..0.264.1853.11j5j1......0....1j2..gws-wiz.......35i39j0i67j0i13j0i22i30j0i8i13i30j0i22i10i30j0i8i13i10i30.M61zuzAavOk&safe=active&ssui=on")
time.sleep(3)
print(driver.find_element_by_id('main').text)
# 单击图书预览按钮
driver.find_element_by_id("pnnext").click()
imageList = set()


# 等待页面加载完成
time.sleep(5)
# 获取已加载的新页面(一次可以加载多个页面,但是重复的页面不能加载到集合中)
pages = driver.find_elements_by_xpath("//descendant::img")
print (pages)
driver.close()

driver.quit()
print("退出Chome")

 

 

 

你可能感兴趣的:(python selenium爬分页(上一页,1, 2, 3, 下一页)(1))