百度文庫內容複製 C# webbrowser+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)
        {
           
            NSoup.Nodes.Document NSoupDoc = NSoup.NSoupClient.Parse(webBrowser1.Document.Body.InnerHtml);

            var strpagecount = NSoupDoc.Body.Select(".page-count").Text;
            if (strpagecount.Contains("/"))
            {
                strpagecount = strpagecount.Replace("/", "");
            }
            int pagecount = 0;
            if (!int.TryParse(strpagecount, out  pagecount))
            {
                MessageBox.Show("頁數處理失敗");
                return;
            }
            StringBuilder content = new StringBuilder();
            for (int i = 0; i < pagecount; i++)
            {
                content.Append(NSoupDoc.Body.Select("#pageNo-"+(i+1)).Text);
            }

            Form2 frm = new Form2();
            frm.richTextBox1.Text= content.ToString();
            frm.Show();

        }

        private void button2_Click(object sender, EventArgs e)
        {
            webBrowser1.Url = new Uri(textBox1.Text);
        }
    }
}

附件下載

文中內容可查看Linux安裝Oracle12C

 

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