【java基础】Jsoup连接URL

原创
2018/02/07 09:13
阅读数 88

1、代码 

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
0 收藏
分享
加载中
更多评论
打赏
0 评论
0 收藏
0
分享
OSCHINA
登录后可查看更多优质内容
返回顶部
顶部