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

版权声明:本文为博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/ever_peng/article/details/88820661
# 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

 

展开阅读全文

没有更多推荐了,返回首页