代码
//获取论坛最新贴
public string GetBBSTopic(int pageSize)
{
StringBuilder builder = new StringBuilder();
string url = "http://www.globevisa.com.cn/vbb/forumdisplay.php?f=7";//投资移民
string content = WebUtils.PostResponse(url, "");
string pattern = "<a(.*?)href=\"(.*?)\">(.*?)</a>";
// pattern = "\n<li><span class=\"middate\">2009-05-22 11:30</span>\n[<a target=\"_blank\" href=\"http://stock.eastmoney.com/company/1175.html\">金证顾问</a>] <a target=\"_blank\" href=\"http://news2.eastmoney.com/090522,1049,1087911.html\">午评:银行企稳 助大盘反弹</a></li>";
//时间 类别URL 类别 资讯URL 资讯
Regex r = new Regex(pattern, RegexOptions.Singleline);
MatchCollection mc = r.Matches(content);
int num = 0;
foreach (Match m in mc)
{
string aUrl = m.Result("$2");
string title = m.Result("$3");
if (aUrl.IndexOf("showthread.php") != -1 && title.Length > 4 && title.IndexOf("<img") == -1)
{
//useful
if (num < pageSize)
{
builder.Append("<li class=\"bbsLi\">\r\n");
builder.AppendFormat("<a href=\"http://www.globevisa.com.cn/vbb/{0}\" target='_blank' title=\"{2}\">{1}</a>\r\n", aUrl,StringUtils.GetGoodString(WebUtils.FilterHtml(title),24),title);
builder.Append("</li>\r\n");
}
else
{
break;
}
num++;
}
}
return builder.ToString();
}
public string GetBBSTopic(int pageSize)
{
StringBuilder builder = new StringBuilder();
string url = "http://www.globevisa.com.cn/vbb/forumdisplay.php?f=7";//投资移民
string content = WebUtils.PostResponse(url, "");
string pattern = "<a(.*?)href=\"(.*?)\">(.*?)</a>";
// pattern = "\n<li><span class=\"middate\">2009-05-22 11:30</span>\n[<a target=\"_blank\" href=\"http://stock.eastmoney.com/company/1175.html\">金证顾问</a>] <a target=\"_blank\" href=\"http://news2.eastmoney.com/090522,1049,1087911.html\">午评:银行企稳 助大盘反弹</a></li>";
//时间 类别URL 类别 资讯URL 资讯
Regex r = new Regex(pattern, RegexOptions.Singleline);
MatchCollection mc = r.Matches(content);
int num = 0;
foreach (Match m in mc)
{
string aUrl = m.Result("$2");
string title = m.Result("$3");
if (aUrl.IndexOf("showthread.php") != -1 && title.Length > 4 && title.IndexOf("<img") == -1)
{
//useful
if (num < pageSize)
{
builder.Append("<li class=\"bbsLi\">\r\n");
builder.AppendFormat("<a href=\"http://www.globevisa.com.cn/vbb/{0}\" target='_blank' title=\"{2}\">{1}</a>\r\n", aUrl,StringUtils.GetGoodString(WebUtils.FilterHtml(title),24),title);
builder.Append("</li>\r\n");
}
else
{
break;
}
num++;
}
}
return builder.ToString();
}