81,091
社区成员
发帖
与我相关
我的任务
分享
System.getProperties().setProperty("proxySet", "true");
//设置你的主机
System.getProperties().setProperty("http.proxyHost", "xxx");
//设置你的端口
System.getProperties().setProperty("http.proxyPort", "xxx");
StringBuilder json = new StringBuilder();
try {
URL oracle = new URL(url);
HttpURLConnection yc = (HttpURLConnection) oracle.openConnection();
yc.setDoOutput(true);
yc.setRequestMethod("GET");
BufferedReader in = new BufferedReader(new InputStreamReader(yc
.getInputStream()));
String inputLine = null;
while ((inputLine = in.readLine()) != null) {
json.append(inputLine);
}
in.close();
} catch (MalformedURLException e) {
} catch (IOException e) {
}
System.out.println(json.toString());
String path="http://open.weibo.com/";
Parser parser=new Parser(path);
parser.setEncoding("utf-8");
NodeList list=parser.parse(null);
System.out.println("<---->");
System.out.println(list.toHtml());
System.out.println("<---->");
我测试了下。html解析 api.weibo.com 可以的。不是他那主机的问题。你测试下可以不需要 htmlparser.jar
import org.htmlparser.Parser;
import org.htmlparser.util.NodeList;