C# 強大的網頁處理類NSoup

地址: https://github.com/GeReV/NSoup

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;

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

        private void button1_Click(object sender, EventArgs e)
        {
            WebClient webClient = new WebClient();
            string htmlString = Encoding.GetEncoding("UTF-8").GetString(webClient.DownloadData("https://blog.csdn.net/lw112190/article/details/106143263"));

            NSoup.Nodes.Document NSoupDoc = NSoup.NSoupClient.Parse(htmlString);

            var title = NSoupDoc.Body.Select(".title-article").Html();

            textBox1.Text = title;
        }
    }
}

效果

附件下載 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章