爬虫学习,selenium2

from selenium import webdriver
from time import sleep
from lxml import etree

url = 'http://125.35.6.84:81/xk/'
bro = webdriver.Chrome(executable_path='./chromedriver')
bro.get(url)
page_text_list = []#每一页的页面源码数据
sleep(2)

#捕获当前页面对应的页面源代码数据
page_text = bro.page_source   #当前页面全部加载后对应的所有的数据
page_text_list.append(page_text)

#点击下一页
for i in range(3):
    next_page = bro.find_element_by_xpath('//*[@id="pageIto_next"]')
    next_page.click()
    sleep(1)
    page_text_list.append(bro.page_source)
    
for page_text in page_text_list:
    tree = etree.HTML(page_text)
    li_list = tree.xpath('//*[@id="gzlist"]/li')
    for li in li_list:
        name = li.xpath('./dl/@title')[0]
        print(name)
    
sleep(2)
bro.quit()

你可能感兴趣的:(笔记)