JSoup:连接方法中的 BaseURL
JSoup: BaseURL in connect method
我有这个代码:
String sitePath = "http://www.google.net/";
Document doc = Jsoup.connect(sitePath).get();
Elements elements = doc.select("body");
manipulateElements(elements);
long before = System.currentTimeMillis();
File fileDir = new File("google.html");
Writer out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(fileDir), "UTF8"));
out.write(doc.toString());
out.flush();
out.close();
如何为所有数据(样式、img...)设置绝对 url?
希望对您有所帮助。
图片。
Elements imgElements = doc.select("img");
for (Element element : imgElements) {
element.attr("src", element.attr("abs:src"));
}
链接
Elements hrefElements = doc.select("a");
for (Element element : hrefElements) {
element.attr("href", element.attr("abs:href"));
}
样式
Elements linkElements = doc.head().select("link");
for (Element element : linkElements) {
element.attr("href", element.attr("abs:href"));
}
我有这个代码:
String sitePath = "http://www.google.net/";
Document doc = Jsoup.connect(sitePath).get();
Elements elements = doc.select("body");
manipulateElements(elements);
long before = System.currentTimeMillis();
File fileDir = new File("google.html");
Writer out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(fileDir), "UTF8"));
out.write(doc.toString());
out.flush();
out.close();
如何为所有数据(样式、img...)设置绝对 url?
希望对您有所帮助。
图片。
Elements imgElements = doc.select("img");
for (Element element : imgElements) {
element.attr("src", element.attr("abs:src"));
}
链接
Elements hrefElements = doc.select("a");
for (Element element : hrefElements) {
element.attr("href", element.attr("abs:href"));
}
样式
Elements linkElements = doc.head().select("link");
for (Element element : linkElements) {
element.attr("href", element.attr("abs:href"));
}