
离线保存浏览器网页
发布日期:2021-05-14 05:15:24
浏览次数:18
分类:精选文章
本文共 4701 字,大约阅读时间需要 15 分钟。
--���������������������������
1.fiddler ���������Google ���������������������������������
3.java saving ������������
package c;import java.io.BufferedReader;import java.io.ByteArrayOutputStream;import java.io.File;import java.io.FileInputStream;import java.io.FileOutputStream;import java.io.InputStream;import java.io.InputStreamReader;import java.net.HttpURLConnection;import java.net.URL;public class test { public static void main(String argv[]) { String filePath = "C:\\Users\\Administrator\\Desktop\\feed.txt"; // String filePath = "C:\\Users\\Administrator\\Desktop\\error.txt"; readTxtFile(filePath); } /** * ���������Java������txt��������������� * ��������� * 1������������������������ * 2��������������������������������������������������������� * 3������������������������������ * ��������������������������������� * @param filePath */ public static void readTxtFile(String filePath) { try { String encoding = "GBK"; File file = new File(filePath); if (file.isFile() && file.exists()) { InputStreamReader read = new InputStreamReader(new FileInputStream(file), encoding); BufferedReader bufferedReader = new BufferedReader(read); String lineTxt = null; String tmp = ""; while ((lineTxt = bufferedReader.readLine()) != null) { doline(lineTxt); } read.close(); } else { System.out.println("������������������������"); } } catch (Exception e) { System.out.println("������������������������"); e.printStackTrace(); } } public static void doline(String str) { try { String savepath = "C:\\Users\\Administrator\\Desktop\\"; String home = "http://grouek.com/"; String name = str.replace(home, ""); String tmp = name; if (!tmp.contains(".")) { // ������������html������ System.out.println("html:" + str); } else { tmp = savepath + tmp; // ������������������������������������ tmp = tmp.substring(0, tmp.lastIndexOf("/")); String last = tmp; String lastone = last; if (last.contains("/")) { try { last = last.substring(0, last.lastIndexOf("/")); } catch (Exception e) { // ��������������������������� } lastone = last; try { lastone = lastone.substring(0, lastone.lastIndexOf("/")); } catch (Exception e) { // ��������������������������� } } // ��������������� if (!new File(lastone).isDirectory()) { new File(lastone).mkdir(); } if (!new File(last).isDirectory()) { new File(last).mkdir(); } if (!new File(tmp).isDirectory()) { new File(tmp).mkdir(); } System.out.println("..."+name); sendImageFile(home + name, savepath + name); } } catch (Exception e) { System.out.println("test.doline()" + str); e.printStackTrace(); } } public static void deal(String url, String path) { try { String tmp = path; // ������������������������������������ tmp = tmp.substring(0, tmp.lastIndexOf("/")); String last = tmp; tmp = tmp.substring(0, tmp.lastIndexOf("/")); if (!new File(tmp).isDirectory()) { new File(tmp).mkdir(); } if (!new File(last).isDirectory()) { new File(last).mkdir(); } sendImageFile(url, path); System.out.print("������������... " + url); } catch (Exception e) { System.out.println("���������������" + e.getMessage()); e.printStackTrace(); } } private static String sendImageFile(String url, String path) { try { // ������������������������������������������������������ URL url2 = new URL(url); HttpURLConnection httpUrl = (HttpURLConnection) url2.openConnection(); httpUrl.setRequestProperty("Accept", "*/*"); httpUrl.setRequestProperty("Connection", "Keep-Alive"); httpUrl.setRequestProperty("User-Agent", "Mozilla/4.0 (Windows NT 5.1;SV1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.0.0 Safari/537.36"); // ������������������������ httpUrl.setRequestProperty("Content-Type", "image/jpeg"); httpUrl.connect(); InputStream inStream = httpUrl.getInputStream(); ByteArrayOutputStream outStream = new ByteArrayOutputStream(); byte[] buffer = new byte[4 * 1024]; int len = 0; while ((len = inStream.read(buffer)) != -1) { outStream.write(buffer, 0, len); } inStream.close(); writeImageToDisk(outStream.toByteArray(), path); } catch (Exception e) { e.printStackTrace(); } return ""; } private static void writeImageToDisk(byte[] img, String fileName) { try { File file = new File(fileName); FileOutputStream fops = new FileOutputStream(file); fops.write(img); fops.flush(); fops.close(); } catch (Exception e) { e.printStackTrace(); } }
发表评论
最新留言
表示我来过!
[***.240.166.169]2025年04月19日 04时41分57秒
关于作者

喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
IDEA 2019 安装 mybatis-plus插件
2021-05-14
div 实现光标悬停变成手型
2021-05-14
layer.confirm 无效
2021-05-14
Java 回调机制
2021-05-14
7、回归和特征选择
2021-05-14
pycharm使用(新建工程、字体修改、调试)
2021-05-14
什么是Numpy、Numpy教程
2021-05-14
Python学习笔记——元组
2021-05-14
异常声音检测
2021-05-14
PCB学习笔记——AD17如何添加新的封装
2021-05-14
numpy版本问题
2021-05-14
无法打开文件“opencv_world330d.lib”的解决办法
2021-05-14
maven项目通过Eclipse上传到svn上面,再导入到本地出现指定的类找不到的问题
2021-05-14
maven 项目部署到tomcat下 没有class文件
2021-05-14
算法训练 未名湖边的烦恼(递归,递推)
2021-05-14
算法训练 完数(循环,数学知识)
2021-05-14
什么是接口
2021-05-14