欢迎您访问我爱IT技术网,今天小编为你分享的编程技术是:【C# 实现抓取网站页面内容的实例方法】,下面是详细的讲解!
C# 实现抓取网站页面内容的实例方法
protected void Enter_Click(object sender, EventArgs e)
{
WebClient we=new WebClient(); //主要使用WebClient类
byte[] myDataBuffer;
myDataBuffer=we.DownloadData(txtURL.Text); //该方法返回的是 字节数组,所以需要定义一个byte[]
string download=Encoding.Default.GetString(myDataBuffer); //对下载的数据进行编码
//通过查询源代码,获取某两个值之间的新闻内容
int startIndex=download.IndexOf("<!-- publish_helper name='要闻-新闻' p_id='1' t_id='850' d_id='1' -->");
int endIndex=download.IndexOf("<!-- publish_helper name='要闻-财经' p_id='30' t_id='98' d_id='1' -->");
string temp=download.Substring(startIndex, endIndex - startIndex + 1); //截取新闻内容
lblMessage.Text=temp;//显示所截取的新闻内容
}
关于C# 实现抓取网站页面内容的实例方法的用户互动如下:
相关问题:
答: >>详细
相关问题:
答: >>详细
相关问题:
答: >>详细
- 【asp】asp.net url重写浅谈-net-url重写
- 【创建】ASP.NET Web API教程 创建域模型的方法详
- 【页面打印】关于ASP.NET页面打印技术的常用方法
- 【MVC5】MVC 5 第一章 创建MVC 5 web应用程序-net
- 【服务器】asp.net页面状态管理cookie和服务器状
- 如何取消.net后台线程的执行
- 【ajax】asp.net下ajax.ajaxMethod使用方法-ajaxM
- 【WeakReference】WeakReference(弱引用)让GC需要
- 【ajax格式】asp.net中在用ajax格式传递数据到asp
- 【字符文本】asp.net 数据绑定 使用eval 时候报
- 评论列表(网友评论仅供网友表达个人看法,并不表明本站同意其观点或证实其描述)
-
