python 爬虫,起点完结榜前100榜单

# coding:utf-8
from selenium import webdriver
i = 0
ph = 1
driver = webdriver.Firefox()
driver.get('https://www.qidian.com/rank/fin')  # 要打开的网页
for r in range(5):
    books = driver.find_elements_by_class_name('book-mid-info')  # 定位包含图书介绍的div
    for book in books:
        bookall = book.text  # 获取div的text内容
        fg = bookall.split("\n")
        print("排行:" + str(ph))
        print("书名:" + fg[0])
        print("作者:" + fg[1])
        print("简介:" + fg[6] + '\n')
        i += 1
        ph += 1
        if ph == 101:  # 判断排行数是否到100
            driver.quit()
            exit()
        if i == 20:  # 每页20本图书,超过20后点击下一页
            driver.find_element_by_css_selector('.lbf-pagination-next').click()
            i = 0
            continue

 

posted @ 2019-03-26 15:00  阿鹏2019  阅读(303)  评论(0编辑  收藏  举报