How to add proxy support to Jsoup?

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

    System.setProperty("http.proxyHost", "192.168.5.1");
    System.setProperty("http.proxyPort", "1080");
    Document doc = Jsoup.connect("www.google.com").get();
    

    This is wrong solution, because parsing is usually multithreaded and we usually need to change proxies. This code sets only one proxy for all threads. So better to not use Jsoup.Connection.

提交回复
热议问题