爬取起点小说总排行榜

编程入门 行业动态 更新时间:2024-10-12 10:26:24

爬取<a href=https://www.elefans.com/category/jswz/34/1766219.html style=起点小说总排行榜"/>

爬取起点小说总排行榜

功能:在表格中按排名 显示小说名字 作者 类型 状态 简介和字数
代码:import xlwt
import requests
from lxml import etree
import time
all_info_list = []

def get_info(url):
html = requests.get(url)
selector = etree.HTML(html.text)
infos = selector.xpath('//ul[@class="all-img-list cf"]/li')

for info in infos:
title = info.xpath('div[2]/h4/a/text()')[0]
author = info.xpath('div[2]/p[1]/a[1]/text()')[0]
style_1 = info.xpath('div[2]/p[1]/a[2]/text()')[0]
style_2 = info.xpath('div[2]/p[1]/a[3]/text()')[0]
style = style_1+'·'+style_2
complete = info.xpath('div[2]/p[1]/span/text()')[0]
introduce = info.xpath('div[2]/p[2]/text()')[0].strip()
word = info.xpath('div[2]/p[3]/span/text()')[0].strip('万字')
info_list = [title,author,style,complete,introduce,word]
all_info_list.append(info_list)
time.sleep(1)

if __name__ == '__main__':
urls = ['/?page={}'.format(str(i)) for i in range(1,200)]
for url in urls:
get_info(url)
header = ['title','author','style','complete','introduce','word']
book = xlwt.Workbook(encoding='utf-8')
sheet = book.add_sheet('Sheetl')
for h in range(len(header)):
sheet.write(0, h, header[h])
i = 1
for list in all_info_list:
j = 0
for data in list:
sheet.write(i, j, data)
j += 1
i += 1
book.save('xiaoshuo.xls')
问题:- -爬取文件过大 可能网速慢 生成文件速度太慢

转载于:.html

更多推荐

爬取起点小说总排行榜

本文发布于:2023-06-29 08:32:42,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/942153.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:起点   总排行榜   小说

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!