---
title: "Java Read Html"
author: "roddy"
date: "2016-07-28T14:37:29Z"
tags: []
categories: ["编程语言"]
slug: "java-read-html"
draft: false
lastmod: "2016-07-28T14:37:29Z"
id: 2314083
url: "https://roddy.iteye.com/blog/2314083"
---

**Need Jar:**
jsoup-1.8.1.jar




```java

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());
			}
		}
	}

```