[Java] 纯文本查看 复制代码
import java.io.IOException;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
public class Demo {
public static void main(String[] args) {
try{
// 代理服务器(产品官网 www.16yun.cn)
final static String ProxyHost = "t.16yun.cn";
final static String ProxyPort = "31111";
System.setProperty("http.proxyHost", ProxyHost);
System.setProperty("https.proxyHost", ProxyHost);
System.setProperty("http.proxyPort", ProxyPort);
System.setProperty("https.proxyPort", ProxyPort);
// 代理验证信息
final static String ProxyUser = "username";
final static String ProxyPass = "password";
System.setProperty("http.proxyUser", ProxyUser);
System.setProperty("http.proxyPassword", ProxyPass);
System.setProperty("https.proxyUser", ProxyUser);
System.setProperty("https.proxyPassword", ProxyPass);
// 设置IP切换头
final static String ProxyHeadKey = "Proxy-Tunnel";
// 设置Proxy-Tunnel
Random random = new Random();
int tunnel = random.nextInt(10000);
String ProxyHeadVal = String.valueOf(tunnel);
// 处理异常、其他参数
String url=“http://www.weather.com.cn”;
Document doc = Jsoup.connect(url).timeout(3000).header(ProxyHeadKey, ProxyHeadVal).get();
if(doc != null) {
System.out.println(doc.body().html());
}
}catch (IOException e)
{
e.printStackTrace();
}
}
}