文章目录
1.Jsoup
JSON有两种获取方式
第一种:
Document document = Jsoup.parse(file,"UTF-8");
第二种
Document document = Jsoup.connect(url);
2.JSoupUtils
public class GetHtmlUtils {
/**
* @Description: 通过JSoup获取到新闻列表html
* @Param: [pathname] html路径
* @return: java.lang.String 返回html的字符串
* @Author: 董云川
* @Date: 2021/7/28
*/
public static String getHtmlByJSoup(String pathname) throws IOException {
File file = new File(pathname);
Document document = Jsoup.parse(file,"UTF-8");
String html = document.toString();
// System.out.println(html);
return html;
// Element elementse = document.getElementById("copyrightId");
// System.out.println(elementse.text());
}
public static Document getHtmlByURL(String pathname) throws IOException {
//设置连接时长,防止不断请求
Document document = Jsoup.connect(pathname)
.timeout(8000)//超时时间
.get();;
return document;
}
}