本文提供方法可以通过rss简单取得csdn帖子URL.
方法实现基本原理 :通过HttpURLConnection发送请求并取得返回字符串.用正则表达式匹配帖子URL.
public void SendURLPost() throws IOException {
//rss的URL
String urlStr = "http://forum.youkuaiyun.com/Rss/J2SE/UnClosedList";
URL url = new URL(urlStr);
HttpURLConnection httpURLConnection = (HttpURLConnection) url
.openConnection(); // 获取连接
httpURLConnection.setRequestMethod("POST"); // 设置请求方法为POST, 也可以为GET
httpURLConnection.setDoOutput(true);
// StringBuffer param = new StringBuffer("ArticleId="); //请求URL的查询参数
// param.append(articleId);
OutputStream os = httpURLConnection.getOutputStream();
// os.write(param.toString().getBytes());
os.flush();
os.close();
InputStream is = httpURLConnection.getInputStream();
BufferedReader br = new BufferedReader(new InputStreamReader(is,
"utf-8"));
StringBuilder sb = new StringBuilder();
while (br.read() != -1) {
sb.append(br.readLine());
}
String content = new String(sb);
br.close();
is.close();
String regEx = "(.*?)";
//Pattern.CASE_INSENSITIVE启用不区分大小写模式
Pattern p = Pattern.compile(regEx,Pattern.CASE_INSENSITIVE);
Matcher m = p.matcher(content);
while(m.find())
{
System.out.println(m.group(1));
}
}