使用WebClient制作一下简单的采集器
2010-10-09 09:11
405 查看
输入url把网页内容抓下来,然后再加工处理,保存到数据库中,这应该是采集器的原理。
如果要使用C#做的话,就要用WebClient类了。
大气象
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Net;
namespace FirstWebClient
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
WebClient _client = new WebClient();
_client.BaseAddress = "http://www.cnblogs.com";
_client.Headers.Add("Accept", "image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*");
_client.Headers.Add("Accept-Language", "zh-cn");
_client.Headers.Add("UA-CPU", "x86");
//_client.Headers.Add("Accept-Encoding","gzip, deflate");
_client.Headers.Add("User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)");
System.IO.Stream objStream = _client.OpenRead("/");
System.IO.StreamReader _read = new System.IO.StreamReader(objStream, System.Text.Encoding.UTF8);
textBox1.Text = _read.ReadToEnd();
}
}
}
参考:/article/5506445.html
如果要使用C#做的话,就要用WebClient类了。
大气象
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Net;
namespace FirstWebClient
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
WebClient _client = new WebClient();
_client.BaseAddress = "http://www.cnblogs.com";
_client.Headers.Add("Accept", "image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*");
_client.Headers.Add("Accept-Language", "zh-cn");
_client.Headers.Add("UA-CPU", "x86");
//_client.Headers.Add("Accept-Encoding","gzip, deflate");
_client.Headers.Add("User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)");
System.IO.Stream objStream = _client.OpenRead("/");
System.IO.StreamReader _read = new System.IO.StreamReader(objStream, System.Text.Encoding.UTF8);
textBox1.Text = _read.ReadToEnd();
}
}
}
参考:/article/5506445.html
相关文章推荐
- 利用PHP制作简单的内容采集器的代码
- 【cocos2d-x】如何使用Cocos2D-x制作一款简单的iphone&Android游戏①
- iOS——制作简单的View时系统方法的使用
- 如何使用ASP.NET制作简单的验证码
- HTML 使用表格制作简单的个人简历
- Git的初次使用 ; Git常用命令查询 ; Git push ; Git pull 2011-12-16 17:32 在介绍安装和简单使用前,先看一下百度百科中的简介吧: ———————————
- 使用bootstrap简单制作Tab切换页
- 使用construct2制作一个简单的游戏
- 简单记录一下makefile的使用
- 使用.NET REACTOR使用方法,制作软件许可证,做一个简单的许可证系统步骤
- ckeditor的简单使用以及多张图片上传插件的制作
- 在使用jQuery+HTML+Javascript的简单例子---很容易的制作双色表格
- python3使用pyqt5制作一个超简单浏览器
- 19. 如何使用GameCenter制作一个简单的多人游戏教程:第二部分
- Git的初次使用 ; Git常用命令查询 ; Git push ; Git pull 2011-12-16 17:32 在介绍安装和简单使用前,先看一下百度百科中的简介吧: ———————————
- 大家一起讨论简称论-关于简单Selector的制作与使用 (Production and Use)
- css3 befor after 简单使用 制作时尚焦点图相框
- 简单介绍一下阿里巴巴矢量图标库的使用
- 简单说一下NA 模拟器的安装与使用
- 使用zTree制作简单异步加载树形结构,支持增删改拖动