添加相关的dll(Interop.MSXML2.dll)

 //得到远程html

//url是要获取的页面的url
public string GetRemoteHtmlCode(string Url)
{
string s = null;
try
{
MSXML2.XMLHTTP _xmlhttp = new MSXML2.XMLHTTP();
_xmlhttp.open("GET", Url, false, null, null);
_xmlhttp.send("");
if (_xmlhttp.readyState == 4)
{
//编码 防止乱码
s = System.Text.Encoding.UTF8.GetString((byte[])_xmlhttp.responseBody);

//s = System.Text.Encoding.GetEncoding("GB2312").GetString((byte[])_xmlhttp.responseBody);
}
}
catch
{

}
return s;
}
   //解析通用类

//wordsBegin获取界面的相关信息的开始字符

//wordsEnd获取界面的相关信息的结束字符
public string ParseWebCode(string code, string wordsBegin, string wordsEnd)
{
string Element = "";
Regex regex1 = new Regex("" + wordsBegin + @"(?<element>[\s\S]+?)" + wordsEnd + "", RegexOptions.Compiled | RegexOptions.IgnoreCase);
for (Match match1 = regex1.Match(code); match1.Success; match1 = match1.NextMatch())
{
Element = match1.Groups["element"].ToString();

}
return Element;
}





posted on 2012-02-22 09:50  蜜茶  阅读(368)  评论(1)    收藏  举报