Java爬虫:Scrape Center的ssr3
在需要进行HTTP身份认证的情况下,我们可以手动构造HTTP Authorization Header并加入到Jsoup请求中。
public class Test3 {
public static void main(String[] args) throws Exception{
//设置url
String url = "https://ssr3.scrape.center/page/1";
Test3 t = new Test3();
System.out.println(t.parseJsoup(url));
}
public String parseJsoup(String url) throws IOException {
String username = "admin";
String password = "admin";
String authString = username + ":" + password;
String auth = "Basic " + Base64.getEncoder().encodeToString(authString.getBytes());
Document document = Jsoup.connect(url)
.header("Authorization", auth)//添加认证
.get();
return document.html();
}
}