• 大小: 776KB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2021-05-08
  • 语言: C#
  • 标签: C#  WebBrowser  

资源简介

本人写了个用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.Text.Regularexpressions;
using System.Design;
using System.Windows.Forms.Design;
using System.IO;

namespace GetWebImage
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        private string savePath = System.Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + “\\urlHtml2.txt“;
        private void webBrowser1_Navigated(object sender WebBrowserNavigatedEventArgs e)
        {
            textBox1.Text = webBrowser1.Url.ToString();
            toolStripStatusLabel1.Text = webBrowser1.Url.ToString();
        }

        private void textBox1_KeyPress(object sender KeyPressEventArgs e)
        {
            if (e.KeyChar == 0x0d)
                webBrowser1.Navigate(textBox1.Text);
        }

        private void Form1_Load(object sender EventArgs e)
        {
 
        }
        //刷新
        private void toolStripButton3_Click(object sender EventArgs e)
        {
            webBrowser1.Refresh();
        }
        //停止
        private void toolStripButton4_Click(object sender EventArgs e)
        {
            webBrowser1.Stop();
        }
        //上一页
        private void toolStripButton1_Click(object sender EventArgs e)
        {
            webBrowser1.GoBack();
        }
        //下一页
        private void toolStripButton2_Click(object sender EventArgs e)
        {
            webBrowser1.GoForward();
        }
        //首页
        private void toolStripButton5_Click(object sender EventArgs e)
        {
            webBrowser1.GoHome();
        }
        //导出图片
        private void toolStripButton6_Click(object sender EventArgs e)
        {
            string LocalFileName; //路径
            int PicNum = 0;
            FolderBrowserDialog folderBrowserDialog=new FolderBrowserDialog();
            if (folderBrowserDialog.ShowDialog()==DialogResult.OK)
            {
                 //Regex reg = new Regex(@“(?is)(?<=<\w+[\s\S]*?src=([‘““])?)(https?)?[^““]+(?:jpg|png|gif)(?=\1)“);
                this.Text = “正在解析源码...“;
                //获取网页经Js解析之后的源码
                string _getSoundCode = this.webBrowser1.Document.Body.InnerHtml;
                //保存源码
                System.IO.File.WriteAllText(savePath _getSoundCode System.Text.Encoding.GetEncoding(“utf-8“));
                //System.Diagnostics.Process.Start(savePath);

                 Regex reg = new Regex(@“(?is)(?<=<\w+[\s\S]*?src=([‘““])?)https?[^““]+(?=\1)“);
                 System.Net.WebClient client = new System.Net.WebClient();
                 MatchCollection mc = reg.Matches(_getSoundCode);
                 foreach (Match m in mc)
                 {

                     string expandedName;
             

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2013-07-31 14:35  GetWebImage\
     目录           0  2013-07-31 16:55  GetWebImage\GetWebImage\
     文件        8672  2013-07-31 18:09  GetWebImage\GetWebImage.5.1.ReSharper.user
     文件         875  2013-07-31 14:35  GetWebImage\GetWebImage.sln
     文件       20480  2013-07-31 18:09  GetWebImage\GetWebImage.suo
     目录           0  2013-07-31 14:35  GetWebImage\GetWebImage\bin\
     目录           0  2013-07-31 17:02  GetWebImage\GetWebImage\bin\Debug\
     文件       20992  2013-07-31 18:06  GetWebImage\GetWebImage\bin\Debug\GetWebImage.exe
     文件       32256  2013-07-31 18:06  GetWebImage\GetWebImage\bin\Debug\GetWebImage.pdb
     文件       11600  2013-07-31 18:08  GetWebImage\GetWebImage\bin\Debug\GetWebImage.vshost.exe
     文件         490  2010-03-17 22:39  GetWebImage\GetWebImage\bin\Debug\GetWebImage.vshost.exe.manifest
     文件     1699840  2003-02-21 08:26  GetWebImage\GetWebImage\bin\Debug\System.Design.dll
     目录           0  2013-07-31 15:39  GetWebImage\GetWebImage\DLLS\
     文件     1699840  2003-02-21 08:26  GetWebImage\GetWebImage\DLLS\System.Design.dll
     文件        5069  2013-07-31 18:01  GetWebImage\GetWebImage\Form1.cs
     文件       11780  2013-07-31 18:01  GetWebImage\GetWebImage\Form1.Designer.cs
     文件       13692  2013-07-31 18:01  GetWebImage\GetWebImage\Form1.resx
     文件        2052  2013-07-31 17:03  GetWebImage\GetWebImage\GetUrlIsExist.cs
     文件        3953  2013-07-31 17:02  GetWebImage\GetWebImage\GetWebImage.csproj
     目录           0  2013-07-31 14:35  GetWebImage\GetWebImage\obj\
     目录           0  2013-07-31 14:35  GetWebImage\GetWebImage\obj\x86\
     目录           0  2013-07-31 18:06  GetWebImage\GetWebImage\obj\x86\Debug\
     文件        2164  2013-07-31 14:35  GetWebImage\GetWebImage\obj\x86\Debug\DesignTimeResolveAssemblyReferences.cache
     文件        6408  2013-07-31 18:06  GetWebImage\GetWebImage\obj\x86\Debug\DesignTimeResolveAssemblyReferencesInput.cache
     文件         622  2013-07-31 18:01  GetWebImage\GetWebImage\obj\x86\Debug\GenerateResource.read.1.tlog
     文件         690  2013-07-31 18:01  GetWebImage\GetWebImage\obj\x86\Debug\GenerateResource.write.1.tlog
     文件         891  2013-07-31 18:08  GetWebImage\GetWebImage\obj\x86\Debug\GetWebImage.csproj.FileListAbsolute.txt
     文件       20992  2013-07-31 18:06  GetWebImage\GetWebImage\obj\x86\Debug\GetWebImage.exe
     文件        5366  2013-07-31 18:01  GetWebImage\GetWebImage\obj\x86\Debug\GetWebImage.Form1.resources
     文件       32256  2013-07-31 18:06  GetWebImage\GetWebImage\obj\x86\Debug\GetWebImage.pdb
     文件         180  2013-07-31 17:02  GetWebImage\GetWebImage\obj\x86\Debug\GetWebImage.Properties.Resources.resources
............此处省略46个文件信息

评论

共有 条评论