当前位置: 首页 > news >正文

wordpress 站长统计有什么网站可以做试题

wordpress 站长统计,有什么网站可以做试题,营销品牌策划公司,变色龙app制作平台背景 因为经常出差火车上没网、不方便电子书阅读器批注#xff0c;需要从某网站上批量下载多本书籍的图片并自动打包成PDF文件。 分析 1、尝试获得图片地址#xff0c;发现F12被禁 解决方法#xff1a;使用Chrome浏览器#xff0c;点击右上角三个点呼出菜单#xff0c;…背景 因为经常出差火车上没网、不方便电子书阅读器批注需要从某网站上批量下载多本书籍的图片并自动打包成PDF文件。 分析 1、尝试获得图片地址发现F12被禁 解决方法使用Chrome浏览器点击右上角三个点呼出菜单选择“更多工具”-“开发者工具” 或者使用CtrlShiftC、CtrlShiftI 2、审查元素发现图片地址非常有规律 在class为side-image的div里有一个imgsrc是../files/mobile/1.jpg?220927153454去掉后面的问号部分即可得到/files/mobile/1.jpg通过观察这本书一共有多少页就会有多少个.jpg文件 3、回到栏目页可得到基目录所以批量抓取的大致思路是从栏目页获得基目录然后不断累加一个数直到获得jpg时对方服务器报404错误即可得到刚刚处理的那一页即最后一页。 4、如何从栏目页获得基目录呢 经观察每个page_pc_btm_book_body里都有两个a标签第一个是图片第二个是“在线阅读”按钮但是需要翻页怎么办呢所以需要建立一个变量收集它们每翻一页做一次收集。于是可以写如下收集函数 let books[] function catchBook() {let links document.getElementsByClassName(page_pc_btm_book_body);for (let i in links) {if(!links[i].children||links[i].children.length2)continue;let title links[i].children[0].title;let link links[i].children[0].href;books.push({title,link})} }然后在浏览器里每翻一页在控制台里执行一次catchBook这样书名和基目录就都获得了。 5、如何把JSON导出来呢 在控制台里JSON.stringify(books)把结果复制出来然后到网上随便找一个JSON转Excel的工具转出来即可然后注意把第一行当表头数据复制到第二行开始。 6、最后一步就写个程序从Excel里读出数据把图片都批量抓下来即可下面就说说如何写程序来处理。 需要引的包 dependencygroupIdorg.apache.poi/groupIdartifactIdpoi/artifactIdversion4.1.0/version /dependency dependencygroupIdorg.apache.poi/groupIdartifactIdpoi-ooxml/artifactIdversion4.1.0/version /dependency dependencygroupIdorg.apache.poi/groupIdartifactIdpoi-ooxml-schemas/artifactIdversion4.1.0/version /dependency dependencygroupIdorg.apache.poi/groupIdartifactIdpoi-scratchpad/artifactIdversion4.1.0/version /dependency dependencygroupIdorg.apache.poi/groupIdartifactIdooxml-schemas/artifactIdversion1.4/version /dependency dependencygroupIdcom.itextpdf/groupIdartifactIditextpdf/artifactIdversion5.5.13.3/version /dependency从Excel到实体 先定义一个实体这里我多加了一列type表示类型name就是从上面那个里面获得的titlelink就是上面获得的link属性。 import lombok.Data;Data public class Book {private String type;private String name;private String link; }然后写个ExcelReader import org.apache.poi.ss.usermodel.*; import org.apache.poi.xssf.usermodel.XSSFWorkbook;import java.io.FileInputStream; import java.io.IOException; import java.util.ArrayList; import java.util.Iterator; import java.util.List;public class ExcelReader {public static ListBook readXlsxToList(String filePath) {ListBook bookList new ArrayList();try (FileInputStream fileInputStream new FileInputStream(filePath);Workbook workbook new XSSFWorkbook(fileInputStream)) {Sheet sheet workbook.getSheetAt(0);IteratorRow rowIterator sheet.iterator();// 获取表头第一行并转换为属性数组Row headerRow rowIterator.next();String[] headers getRowDataAsStringArray(headerRow);// 遍历每一行从第二行开始while (rowIterator.hasNext()) {Row row rowIterator.next();Book book new Book();// 遍历每个单元格并根据属性名称设置对应的实体类属性值for (Cell cell : row) {int columnIndex cell.getColumnIndex();if (columnIndex headers.length) {String headerValue headers[columnIndex];String cellValue getCellValueAsString(cell);setBookProperty(book, headerValue, cellValue);}}bookList.add(book);}} catch (IOException e) {e.printStackTrace();}return bookList;}private static String[] getRowDataAsStringArray(Row row) {String[] rowData new String[row.getLastCellNum()];for (Cell cell : row) {int columnIndex cell.getColumnIndex();rowData[columnIndex] getCellValueAsString(cell);}return rowData;}private static String getCellValueAsString(Cell cell) {String cellValue ;if (cell ! null) {switch (cell.getCellType()) {case STRING:cellValue cell.getStringCellValue();break;case NUMERIC:cellValue String.valueOf(cell.getNumericCellValue());break;case BOOLEAN:cellValue String.valueOf(cell.getBooleanCellValue());break;case FORMULA:cellValue cell.getCellFormula();break;default:cellValue ;}}return cellValue;}private static void setBookProperty(Book book, String propertyName, String propertyValue) {switch (propertyName) {case type:book.setType(propertyValue);break;case name:book.setName(propertyValue);break;case link:book.setLink(propertyValue);break;// 添加其他属性default:// 未知属性可以根据需要进行处理break;}} }从实体集合到批量下载成jpg 还需要想办法实现批量下载的功能需要注意的是Windows的默认文件排序是按ASC码排序的会把10.jpg排在2.jpg前面所以需要对页码格式化一下把它变成三位数。 import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.net.HttpURLConnection; import java.net.URL; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import java.util.List;public class ImageDownloader {public static void downloadImages(ListBook bookList, String targetDir) {for (Book book : bookList) {String type book.getType();String name book.getName();String link book.getLink();String basePath targetDir / type / name;int count 1;boolean continueDownload true;if(!new File(basePath).exists()){new File(basePath).mkdirs();}while (continueDownload) {String imgUrl link files/mobile/ count .jpg;String outputPath String.format(%s/%03d.jpg, basePath, count);if (!imageExists(outputPath)) {try {downloadImage(imgUrl, outputPath);System.out.println(Downloaded: outputPath);} catch (IOException e) {System.out.println(Error downloading image: imgUrl);e.printStackTrace();continueDownload false;}} else {System.out.println(Image already exists: outputPath);}count;}}}private static boolean imageExists(String path) {Path imagePath Paths.get(path);return Files.exists(imagePath);}private static void downloadImage(String imageUrl, String outputPath) throws IOException {URL url new URL(imageUrl);HttpURLConnection httpConn (HttpURLConnection) url.openConnection();int responseCode httpConn.getResponseCode();if (responseCode HttpURLConnection.HTTP_OK) {try (InputStream inputStream httpConn.getInputStream();FileOutputStream outputStream new FileOutputStream(outputPath)) {byte[] buffer new byte[4096];int bytesRead;while ((bytesRead inputStream.read(buffer)) ! -1) {outputStream.write(buffer, 0, bytesRead);}}} else {throw new IOException(Server returned response code responseCode);}} }开始批量下载 import java.util.List;public class Test {public static void main(String[] args) {ListBook books ExcelReader.readXlsxToList(C:\\Users\\Administrator\\Desktop\\某某书库.xlsx);String targetDir D:\\书库\\;ImageDownloader.downloadImages(books, targetDir);} }写完执行回去睡一觉 jpg图片批量转成pdf 都下载完之后就可以想办法批量转成PDF格式了。 import com.itextpdf.text.*; import com.itextpdf.text.pdf.PdfWriter;import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.net.MalformedURLException;public class ImageToPdfConverter {public static void convertToPdf(String folderPath, String outputFilePath) {try {// 获取文件夹中的所有jpg文件File folder new File(folderPath);File[] files folder.listFiles((dir, name) - name.toLowerCase().endsWith(.jpg));// 预读第一章图片获得大小Rectangle rect null;if (files.length 0) {return;} else {Image image Image.getInstance(files[0].getAbsolutePath());rect new Rectangle(image.getWidth(), image.getHeight());}// 创建PDF文档对象Document document new Document(rect);document.setMargins(0, 0, 0, 0);// 创建PDF写入器PdfWriter writer PdfWriter.getInstance(document, new FileOutputStream(outputFilePath));writer.setStrictImageSequence(true);// 打开PDF文档document.open();// 遍历图片文件并将其加入到PDF文档中for (File file : files) {Image image Image.getInstance(file.getAbsolutePath());document.add(image);}// 关闭PDF文档document.close();System.out.println(PDF文件生成成功);} catch (FileNotFoundException | DocumentException e) {e.printStackTrace();} catch (MalformedURLException e) {throw new RuntimeException(e);} catch (IOException e) {throw new RuntimeException(e);}}public static void main(String[] args) {String startDirD:\\书库\\开发技术\\;File[] subdirs new File(startDir).listFiles();for (File subdir : subdirs) {if(subdir.isDirectory()){convertToPdf(subdir.getAbsolutePath(), subdir.getAbsolutePath().pdf);}}} }结束 最后把PDF文件传到网盘上手机、平板、电脑随时可以下载离线看非常舒服。 注意自己抓取书籍自己看无所谓但通过网络分享出去是侵犯他人著作权的。
http://www.dnsts.com.cn/news/136842.html

相关文章:

  • 石家庄品牌网站建设做网站卖什么发财
  • 有的网站显示正在建设中wordpress 页面瀑布流
  • 那些网站专门做棋牌推广的民治网站设计圳网站建设公司
  • 公司网站没备案找源码的网站
  • 网站开发费用多少嘉祥网站seo
  • 宝塔自助建站源码石家庄网架公司
  • 宜都网站建设如何自己设计一个网页
  • 什么网站可以做新闻听写网站最近收录
  • 网站建设维护工作职责免费公司网页制作
  • 临安农家乐做网站江苏威达建设有限公司网站
  • 象客企业网站做优化排名上海自动化仪表厂
  • div做网站排版建筑公司网站领导致辞
  • 西安建设工程中心交易网站工程项目建设网站
  • 成都协会网站建设展示型网站多少钱
  • 网站托管服务 优帮云响应式网站设计的规范
  • 大连网站设计培训班wordpress 链接本地化
  • 河北网站建设有限公司云服务器建站
  • 别墅设计 网站模板沈阳网站改版
  • 杭州网站建设zj net宽创国际的展馆设计案例
  • 网站开发进度表常见的网络营销模式
  • 定制设计网站外贸营销型网页设计公司
  • 国外网站打不开怎么解决东盟建设工程有限公司网站
  • 玉溪市住房和城乡建设局网站wordpress 3.6下载
  • 网站怎么做抽奖盐城网站建设系统公司
  • 青海西宁制作网站公司网游开发软件
  • 信誉好的网站建设公司厦门 网站建设 闽icp
  • 高新区做网站的公司网页设计与网站建设 pdf
  • 电脑做网站服务器改端口wordpress5.0编辑器
  • 我要自学网网站卖域名的公司 骗做网站
  • 新开传奇网站曾劲松免费网站建设360