基本信息
源码名称:GoogleBookDownloader WebClient 读取网页源码
源码大小:0.08M
文件格式:.zip
开发语言:C#
更新时间:2016-11-08
   友情提示:(无需注册或充值,赞助后即可获取资源下载链接)

     嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):78630559

本次赞助数额为: 2 元 
   源码介绍

GoogleBookDownloader

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.Web;
using System.Text.RegularExpressions;
using System.Threading;

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

        private void DownloadThread()
        {
            button1.Invoke(new Action(() => { button1.Enabled = false; }));
            UriBuilder parser = new UriBuilder(textBox1.Text);
            String querystr = parser.Query;
            String bookid = HttpUtility.ParseQueryString(querystr).Get("id");
            String outdir = textBox2.Text;
            outdir = outdir   bookid   "\\";
            System.IO.Directory.CreateDirectory(outdir);
            WebClient wc = new WebClient();
            String pagesrc = wc.DownloadString("http://books.google.com/books?id="   bookid   "&pg=1&jscmd=click3");
            MatchCollection matches = Regex.Matches(pagesrc, "\"pid\":\"(?<pid>.*?)\"", RegexOptions.ExplicitCapture);
            String pid;
            String src;
            MatchCollection matches2;
            progressBar1.Invoke(new Action(() => { progressBar1.Maximum = matches.Count - 1; }));
            for (int i = 0; i < matches.Count; i  )
            {
                pid = matches[i].Result("${pid}");
                pagesrc = wc.DownloadString("http://books.google.com/books?id="   bookid   "&pg="   pid   "&jscmd=click3");
                matches2 = Regex.Matches(pagesrc, "\"pid\":\""   pid   "\",\"src\":\"(?<src>.*?)\"", RegexOptions.ExplicitCapture);
                if (matches2.Count == 1)
                {
                    src = matches2[0].Result("${src}");
                    src = src.Replace("\\u0026", "&");
                    wc.DownloadFile(src, outdir   String.Format("{0:0000}", i   1)   ".png");
                }
                progressBar1.Invoke(new Action(() => { progressBar1.Value = i; }));
            }
            MessageBox.Show("Done.");
            progressBar1.Value = 0;
            button1.Invoke(new Action(() => { button1.Enabled = true; }));
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (textBox1.TextLength > 0)
            {
                new Thread(DownloadThread).Start();
            }
            else
            {
                MessageBox.Show("Invalid URL.");
            }
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            textBox2.Text = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory)   "\\";
            linkLabel1.Links[0].LinkData = "http://www.gbooksdownloader.com/";
        }

        private void button2_Click(object sender, EventArgs e)
        {
            FolderBrowserDialog directoryDialog = new FolderBrowserDialog();
            directoryDialog.RootFolder = Environment.SpecialFolder.DesktopDirectory;
            if (directoryDialog.ShowDialog() == DialogResult.OK)
            {
                textBox2.Text = directoryDialog.SelectedPath   "\\";
            }
        }

        private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            System.Diagnostics.Process.Start(e.Link.LinkData.ToString());
        }

    }
}