ITeye博客

Java Read Html

roddy · 2016-07-28 14:37 · Java · 编程语言 · Markdown

Need Jar: jsoup-1.8.1.jar


public static void main(String[] args) {
		String content="";
		try {
			content = executeGet("qq.com","t.qq.com","pgv_pvi=2633264128; RK=AWkaEwm4WM; ptcz=b94a87c80a0a85ceec47cd63566d582d7110bb329e378f2ef066185e9b957333; pt2gguin=o0002442254; ts_refer=url.cn/sorry; wbilang_10000=zh_TW; mb_reg_quick=1; wb_regf=%3B0%3B%3Bapi.t.qq.com%3B0; pgv_info=ssid=s1646546122; ts_last=t.qq.com/snow13000521; pgv_pvid=6340134792; o_cookie=2442254; ts_uid=9369757478");
		} catch (IOException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		org.jsoup.nodes.Document doc = (org.jsoup.nodes.Document) Jsoup.parse(content);
		
    	org.jsoup.nodes.Element element = doc.getElementById("mainWrapper");
    	org.jsoup.nodes.Document doc2 = (org.jsoup.nodes.Document) Jsoup.parse(element.getElementsByClass("avatar").toString());
    	Elements elements = doc2.select("a[href]");
    	String qqUrl = "";
    	for(org.jsoup.nodes.Element ele : elements){
    		qqUrl = ele.attr("href");
    	}
    	
    	//To get region
    	try {
			content = executeGet("qq.com","t.qq.com","pgv_pvi=2633264128; RK=AWkaEwm4WM; ptcz=b94a87c80a0a85ceec47cd63566d582d7110bb329e378f2ef066185e9b957333; pt2gguin=o0002442254; ts_refer=url.cn/sorry; wbilang_10000=zh_TW; mb_reg_quick=1; wb_regf=%3B0%3B%3Bapi.t.qq.com%3B0; pgv_info=ssid=s1646546122; ts_last=t.qq.com/snow13000521; pgv_pvid=6340134792; o_cookie=2442254; ts_uid=9369757478");
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		//System.out.println(content);
		if(content.length()>0){
			org.jsoup.nodes.Document docAuthor = (org.jsoup.nodes.Document) Jsoup.parse(content);
			Elements elementAuthors = docAuthor.getElementsByClass("ico_location");
			if(elementAuthors.size()>0){
				org.jsoup.nodes.Element elementAuthor = elementAuthors.get(0).nextElementSibling();
				System.err.println("==QQ Region==== "+elementAuthor.text());
			}
		}
	}

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。