![]()
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;//引用流
using System.Net;//引用网页
namespace WindowsFormsApplication8
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)//抓取网页,在richtextbox1中显示出网页的源代码
{
WebRequest wr = WebRequest.Create("http;//www.baidu.com/");//输入一个网址
WebResponse wtr = wr.GetResponse();//得到一个网址的回应
Stream a = wtr.GetResponseStream();//用流来读取
StreamReader s = new StreamReader(a,Encoding.Default);//default 防止出乱码
string q= s.ReadToEnd();//定义一个string类型的来接受它
richTextBox1.Text = q;//让文本内容来显示他。
}
}
}