摘取網頁信息C#源碼 待續

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.Net;
using System.IO;

namespace 博客
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string x = textBox2.Text;
            //指定請求
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://"+x+"");
            //得到返回
            HttpWebResponse response = (HttpWebResponse)request.GetResponse();

            //得到流
            Stream recStream = response.GetResponseStream();

            //編碼方式
            Encoding gb2312 = Encoding.GetEncoding("gb2312");

            //指定轉換爲gb2312編碼
            StreamReader sr = new StreamReader(recStream, gb2312);

            //以字符串方式得到網頁內容
            String content = sr.ReadToEnd();

            //將網頁內容顯示在TextBox中
            textBox1.Text = content;

       

 

 

 


        }
    }
}

發佈了34 篇原創文章 · 獲贊 0 · 訪問量 3萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章