W3C api 抓取
生活随笔
收集整理的這篇文章主要介紹了
W3C api 抓取
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
2019獨角獸企業重金招聘Python工程師標準>>>
存檔
W3CIDLFetcher
package canghailan.w3c;import org.jsoup.Jsoup; import org.jsoup.nodes.Document; import org.jsoup.nodes.Element;import java.io.BufferedWriter; import java.io.IOException; import java.net.URISyntaxException; import java.nio.charset.Charset; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import java.nio.file.StandardOpenOption; import java.text.SimpleDateFormat; import java.util.Arrays; import java.util.Date;/*** @author canghailan 2011-12-26 14:54*/ public class W3CIDLFetcher {private static final int TIMEOUT = 60 * 1000; // 1minprivate static final String[] CSS_URLS = {"http://dev.w3.org/csswg/cssom/","http://dev.w3.org/csswg/cssom-view/"};private static final String[] DOM_URLS = {"http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html","http://www.w3.org/TR/DOM-Level-3-Events/"};private static final String[] HTML_URLS = {"http://www.w3.org/TR/html5/Overview.html",};public static String[] fetchAll() throws IOException, URISyntaxException {Path home = Paths.get(W3CIDLFetcher.class.getProtectionDomain().getCodeSource().getLocation().toURI());String timestamp = new SimpleDateFormat("yyyyMMddHHmmssSSS").format(new Date());Path cssIdl = home.resolve("css" + timestamp + ".idl");Path domIdl = home.resolve("dom" + timestamp + ".idl");Path htmlIdl = home.resolve("html" + timestamp + ".idl");fetch(Arrays.asList(CSS_URLS), cssIdl.toString());fetch(Arrays.asList(DOM_URLS), domIdl.toString());fetch(Arrays.asList(HTML_URLS), htmlIdl.toString());return new String[]{cssIdl.toString(), domIdl.toString(), htmlIdl.toString()};}public static void fetch(Iterable<String> urls, String path) throws IOException {for (String url : urls) {fetch(url, path);}}public static void fetch(String url, String path) throws IOException {System.out.println("fetch idl: " + url + " -> " + path);Document doc = Jsoup.connect(url).timeout(TIMEOUT).get();BufferedWriter writer = Files.newBufferedWriter(Paths.get(path), Charset.forName("UTF-8"),StandardOpenOption.WRITE,StandardOpenOption.CREATE,StandardOpenOption.APPEND);for (Element idl : doc.select("pre.idl")) {writer.write(idl.text());writer.write("\n\n");}writer.flush();writer.close();}public static void main(String[] args) throws IOException, URISyntaxException {fetchAll();}}
WebIDLGrammarDownloader
package canghailan.webidl;import org.jsoup.Jsoup; import org.jsoup.nodes.Document; import org.jsoup.nodes.Element; import org.jsoup.select.Elements;import java.io.BufferedWriter; import java.io.IOException; import java.net.URISyntaxException; import java.nio.charset.Charset; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import java.nio.file.StandardOpenOption;/*** @author canghailan 2011-12-26 19:39*/ public class WebIDLGrammarDownloader {private static final int TIMEOUT = 60 * 1000; // 1minpublic static void download() throws IOException, URISyntaxException {Document doc = Jsoup.connect("http://www.w3.org/TR/WebIDL/").timeout(TIMEOUT).get();Elements grammars = doc.select("#appendices .grammar");Path home = Paths.get(WebIDLGrammarDownloader.class.getProtectionDomain().getCodeSource().getLocation().toURI());Path webIdlGrammar = home.resolve("web-idl.g");BufferedWriter writer = Files.newBufferedWriter(webIdlGrammar, Charset.forName("UTF-8"),StandardOpenOption.WRITE,StandardOpenOption.CREATE,StandardOpenOption.TRUNCATE_EXISTING);for (Element grammar : grammars) {for (Element tr : grammar.select("tr")) {writer.write(tr.text());writer.write('\n');}}writer.flush();writer.close();}public static void main(String[] args) throws IOException, URISyntaxException {download();} }
w3c-api:?https://code.google.com/p/es-operating-system/
轉載于:https://my.oschina.net/canghailan/blog/38431
總結
以上是生活随笔為你收集整理的W3C api 抓取的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: linux下测试RTC驱动相关的命令da
- 下一篇: zend 修改默认view路径,添加扩展