jsoup connect の仕方

[ 基本 ]
URL をセットして get すればよい


final String URL = "http://xxxxx/yyy";
Document jsdocall = Jsoup.connect(URL)
                .get();

[ 実践 ]
プロキシ、ユーザーエージェント、ヘッダー、リファラーをセット


  private final String USER_AGENT
          = "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.77 Safari/537.36";

  private final String HEADER_ACCEPT = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
  private final String HEADER_ACCEPT_LANG = "ja,en-US;q=0.7,en;q=0.3";
  private final String HEADER_ACCEPT_ENCODING = "gzip, deflate, br";
  private final String HEADER_REFERER = "https://www.xxxxx/yyyy";

Document jsdoc = Jsoup.connect(this.kwurl)
                .proxy(this.proxyHost, this.proxyPort)
                .userAgent(USER_AGENT)
                .header("Accept", HEADER_ACCEPT)
                .header("Accept-Language", HEADER_ACCEPT_LANG)
                .header("Accept-Encoding", HEADER_ACCEPT_ENCODING)
                .header("Referer", HEADER_REFERER)
                .timeout(10 * 1000)
                .get();

コメントを残す