【java基础】Jsoup连接URL

2019-07-25 14:34:52 浏览数 (2)

1、代码

代码语言:javascript复制
import java.io.IOException;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;

public class Common {

	public static Document getDoc(String url,String cookie,String host,String refefer) throws IOException{
		Document doc = null;
		String doc01 = null;
		doc = Jsoup
				.connect(url)
				.header("Host", host)
				.header("User-Agent",
						" Mozilla/5.0 (Windows NT 6.1; WOW64; rv:58.0) Gecko/20100101 Firefox/58.0")
				.header("Accept", "text/html,application/xhtml xm…plication/xml;q=0.9,*/*;q=0.8")
				.header("Accept-Encoding", "gzip, deflate, br")
				.header("Accept-Language", "zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2")
				.header("Cache-Control", "max-age=0")
				.header("Connection", "keep-alive")
				.header("Cookie", cookie)

				.header("Referer", refefer)
				.header("Upgrade-Insecure-Requests", "1")
				.header("Cache-Control", "max-age=0")
				.timeout(30000)//设置超时30s
				.ignoreContentType(true).get();
		return doc;
	}
	
}

0 人点赞