How to add proxy support to Jsoup?

前端 未结 7 1739
独厮守ぢ
独厮守ぢ 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:38

    Jsoup does support using proxies, since v1.9.1. Connection class has the following methods:

    • proxy(Proxy p)
    • proxy(String host, int port)

    Which you can use it like this:

    Jsoup.connect("...url...").proxy("127.0.0.1", 8080);
    

    If you need authentication, you can use the Authenticator approach mentioned by @Navneet Swaminathan or simply set system properties:

    System.setProperty("http.proxyUser", "username");
    System.setProperty("http.proxyPassword", "password");
    

    or

    System.setProperty("https.proxyUser", "username");
    System.setProperty("https.proxyPassword", "password");
    

提交回复
热议问题