How to add proxy support to Jsoup?

前端 未结 7 1734
独厮守ぢ
独厮守ぢ 2020-11-28 03:47

I am a beginner to Java and my first task is to parse some 10,000 URLs and extract some info out of it, for this I am using Jsoup and it\'s working fine.

7条回答
  •  谎友^
    谎友^ (楼主)
    2020-11-28 04:33

    You might like to add this before running the program

    final String authUser = "USERNAME";
    final String authPassword = "PASSWORD";
    
    
    
    Authenticator.setDefault(
                   new Authenticator() {
                      public PasswordAuthentication getPasswordAuthentication() {
                         return new PasswordAuthentication(
                               authUser, authPassword.toCharArray());
                      }
                   }
                );
    
    ..
    
    System.setProperty("http.proxyHost", "192.168.5.1");
    System.setProperty("http.proxyPort", "1080");
    ..
    

提交回复
热议问题