日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 前端技术 > HTML >内容正文

HTML

离线保存浏览器网页

發(fā)布時間:2023/12/10 HTML 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 离线保存浏览器网页 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

--離線保存瀏覽器網(wǎng)頁

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文件的內(nèi)容 步驟:1:先獲得文件句柄 2:獲得文件句柄當(dāng)做是輸入一個字節(jié)碼流,需要對這個輸入流進行讀取* 3:讀取到輸入流后,需要讀取生成字節(jié)流 4:一行一行的輸出。readline()。 備注:需要考慮的是異常情況* * @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("讀取文件內(nèi)容出錯");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(".")) {// 當(dāng)前處于htmlSystem.out.println("html:" + str);} else {tmp = savepath + tmp;// 3cengtmp = tmp.substring(0, tmp.lastIndexOf("/"));String last = tmp;String lastone = last;if (last.contains("/")) {try {last = last.substring(0, last.lastIndexOf("/"));} catch (Exception e) {// System.out.println("-----------");}lastone = last;try {lastone = lastone.substring(0, lastone.lastIndexOf("/"));} catch (Exception e) {// System.out.println("-----------");}}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) {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("finsh.." + url);}private static String sendImageFile(String url, String path) {String subUrl = "";// System.out.println("test.sendImageFile()"+url+"\t"+path);try {URL url2 = new URL(url);// Log.i("http:send", "http send"+url);HttpURLConnection httpUrl = (HttpURLConnection) url2.openConnection();// 設(shè)置通用的請求屬性httpUrl.setRequestProperty("accept", "*/*");httpUrl.setRequestProperty("connection", "Keep-Alive");httpUrl.setRequestProperty("user-agent","Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1;SV1)");// httpUrl.setRequestProperty("Content-type", "application/text");httpUrl.setRequestProperty("Content-Type", "image/*");// 連接指定的網(wǎng)絡(luò)資源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();}// System.out.println();return subUrl;}/*** 將圖片寫入到磁盤* * @param img* 圖片數(shù)據(jù)流* @param fileName* 文件保存時的名稱*/public static void writeImageToDisk(byte[] img, String fileName)throws Exception {File file = new File("" + fileName);FileOutputStream fops = new FileOutputStream(file);fops.write(img);fops.flush();fops.close();} }

總結(jié)

以上是生活随笔為你收集整理的离线保存浏览器网页的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。