1. 程式人生 > >Jsoup +JavaScript 扒取網站模板 bootstarp

Jsoup +JavaScript 扒取網站模板 bootstarp

1. 心情特別興奮,最近公司要做一個 基於bootstarp的網站 ,由於找不到好的免費模板 目標瞄上了 國外收費的,但是炸眼一看 好多美元啊 ,不行 太貴小子付不起 於是  想到以前扒網站的事情 靈光閃現 扒吧
:先上程式碼 
JAVA
 
package com.test;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

import com.sun.org.apache.xalan.internal.xsltc.cmdline.getopt.GetOpt;

public class HtmlUntil {

	private final static String htmlUrl = "http://themicon.co/theme/angle/v3.3.1/backend-jquery/app/";
	private final static String jsUrl   = "http://themicon.co/theme/angle/v3.3.1/backend-jquery/";

	public static void main(String[] args) {
			// getJs();
		 getCss();
		 
	}

	public static void getHtml() {
		String urls = "lock.html|dashboard.html|";

		String[] urlsList = urls.split("[|]");
		int i = 0;
		for (String s : urlsList) {
			HtmlUntil.writeHtmlinFile(s,htmlUrl);
			System.out.println(i + "===============" + s);
			i++;
		}

	}

	public static void getCss() {
		String  csslist = "vendor/fontawesome/css/font-awesome.min.css|";
		
		String[] urlsList = csslist.split("[|]");
		int i = 0;
		for (String s : urlsList) {
			HtmlUntil.writeHtmlinFile(s,jsUrl);
			System.out.println(i + "===============" + s);
			i++;
		}
		System.out.println("end");
		
		
	}

	public static void getJs() {
		
		String jsList ="vendor/modernizr/modernizr.custom.js|";

		String[] urlsList = jsList.split("[|]");
		int i = 0;
		for (String s : urlsList) {
			HtmlUntil.writeHtmlinFile(s,jsUrl);
			System.out.println(i + "===============" + s);
			i++;
		}
		System.out.println("end");
	}

	public static boolean writeHtmlinFile(String fileName,String url) {

		String html = getHtml(fileName,url);
		boolean flag = true;

		File file = HtmlUntil.createFile(fileName);
		BufferedWriter bw = null;
		try {
			bw = new BufferedWriter(new FileWriter(file, true));
			bw.write(html);
			bw.close();
		} catch (IOException e) {

			flag = false;
			System.out.println(flag + "========" + fileName);
		}

		return flag;

	}

	public static String getHtml(String fileName,String url) {
		 String js ="";

		try {
			
			js = Jsoup.connect(url + fileName).timeout(30 * 1000).ignoreContentType(true).execute().body();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	

		return js;

	}

	private static File createFile(String fileName) {
		
		File file = new File("D:/html/css/" + fileName);
		if (!file.exists()) {
			try {
				file.getParentFile().mkdirs();
				file.createNewFile();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		return file;
	}

}

 

JavaScript  : 很簡單就不細說了 主要操作就是   隨便抓一個網頁
:獲取  css  js  html 路徑

上圖看看結果                                     價格



                                    網頁模板




                                                                     扒下來的