当前位置: 编程技术>.net/c#/asp.net
C#获取网页源码的简单示例
来源: 互联网 发布时间:2014-08-30
本文导语: 代码如下: 代码示例: /// /// 获取指定网页的源文件 /// /// 网页url /// 网页源码 private string getHtml(string url) { try { WebClient myWebClient = new WebClient(); byte[] myDataBuffer = myWebClient.DownloadData(url); return Encoding.Default.GetString...
代码如下:
代码示例:
///
/// 获取指定网页的源文件
///
/// 网页url
/// 网页源码
private string getHtml(string url)
{
try
{
WebClient myWebClient = new WebClient();
byte[] myDataBuffer = myWebClient.DownloadData(url);
return Encoding.Default.GetString(myDataBuffer);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
throw;
}
}
///////////////截取获得的源码
阿维护公平噶平稳123456wegweg
//若要截取123456
string str1="阿维护公平噶平稳";
strint str2="123456wegweg";
//当然 str1 和 str2 只是替代品
Regex retex = new Regex("(?is)(?
/// 获取指定网页的源文件
///
/// 网页url
/// 网页源码
private string getHtml(string url)
{
try
{
WebClient myWebClient = new WebClient();
byte[] myDataBuffer = myWebClient.DownloadData(url);
return Encoding.Default.GetString(myDataBuffer);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
throw;
}
}
///////////////截取获得的源码
阿维护公平噶平稳123456wegweg
//若要截取123456
string str1="阿维护公平噶平稳";
strint str2="123456wegweg";
//当然 str1 和 str2 只是替代品
Regex retex = new Regex("(?is)(?