基本要求:
基于控制台开发“全书网综合管理系统”,实现以下功能。
登录,密码修改,增加数据(键盘录入,文件导入[csv,xls,json等],网页爬取),修改,删除,查询(按名称查询),统计(每种题材的数量),记录导出至文件等功能
5.全书网
https://www.xs4.cc/all.html
要求爬取的小说不少于100部,记录每本小说的id,名称,作者,题材,字数,点击数,推荐票,简介,章节数等信息存放在mysql数据库中
项目要求:
全书网Java爬取数据
- 写回答
- 好问题 0 提建议
- 关注问题
- 邀请回答
-
39条回答 默认 最新
- CSDN专家-sinJack 2024-12-11 16:23关注
获得0.20元问题酬金 package com.baweihu.wler; import java.util.UUID; import com.alibaba.fastjson.JSONObject; import com.baweihu.entity.Novel; import com.baweihu.util.FileUtil; import com.baweihu.util.ImageDownload; import us.codecraft.webmagic.Page; import us.codecraft.webmagic.Site; import us.codecraft.webmagic.Spider; import us.codecraft.webmagic.processor.PageProcessor; import us.codecraft.webmagic.selector.Html; /** * @author huluwa * @version 1.0.0 * */ public class QuanShu implements Runnable,PageProcessor { // 抓取网站的相关配置,可以包括编码、抓取间隔1s、重试次数等 private Site site = Site.me().setCharset("gbk").setRetryTimes(0).setSleepTime(0).setTimeOut(8000); private int start; private int end; public QuanShu(int start, int end) { super(); this.start = start; this.end = end; } public QuanShu() { super(); } public Site getSite() { return site; } public void run() { for(; start < end; start ++) { Spider.create(new QuanShu()).addUrl("http://www.quanshuwang.com/book_" + start + ".html").thread(2).run(); } } /** * @param length:长度 * threadNum:要开启线程的数量 * */ public synchronized void handleList(int length, int threadNum) { //如果线程个数不能被整除则多加个线程来处理剩余的数据 int t = length % threadNum == 0 ? length / threadNum : length / (threadNum - 1); for (int i = 0; i < threadNum; i++) { int start = i * t; int end = (i + 1) * t; QuanShu test = new QuanShu(start, end); new Thread(test).start(); } } public void process(Page page) { try { Html html = page.getHtml(); String title = html.xpath("/html/head/meta[5]/@content").get(); if(null == title) { return; //获取不到小说名字 就表示为null 不爬这条数据 } String author = html.xpath("/html/head/meta[9]/@content").get(); String classfy =html.xpath("/html/head/meta[8]/@content").get(); String isFinish =html.xpath("/html/head/meta[11]/@content").get(); String coverUrl =html.xpath("/html/head/meta[7]/@content").get(); String chapterUrl =html.xpath("/html/head/meta[14]/@content").get(); String introduce =html.xpath("/html/head/meta[6]/@content").get(); String updateTime =html.xpath("/html/head/meta[12]/@content").get(); String json = JSONObject.toJSONString(new Novel(title, author, classfy, isFinish, introduce, coverUrl, chapterUrl, updateTime)); String no = UUID.randomUUID().toString().replace("-", ""); FileUtil.writeToFile("file/" + no + "/info.txt", json); ImageDownload.downloadPicture(coverUrl, "file/" + no + "/cover.jpg"); } catch (Exception e) { e.printStackTrace(); } } public static void main(String[] args) { QuanShu qs = new QuanShu(); qs.handleList(95730, 12); } }
解决 无用评论 打赏 举报
悬赏问题
- ¥15 PADS Logic 原理图
- ¥15 PADS Logic 图标
- ¥15 电脑和power bi环境都是英文如何将日期层次结构转换成英文
- ¥20 气象站点数据求取中~
- ¥15 如何获取APP内弹出的网址链接
- ¥15 wifi 图标不见了 不知道怎么办 上不了网 变成小地球了
- ¥50 STM32单片机传感器读取错误
- ¥50 power BI 从Mysql服务器导入数据,但连接进去后显示表无数据
- ¥15 (关键词-阻抗匹配,HFSS,RFID标签天线)
- ¥15 机器人轨迹规划相关问题