zoukankan      html  css  js  c++  java
  • Webbrowser 取消下载提示框

    在使用Webbrowser抓取网页信息时,碰到需要下载文件,这时需要用户介入操作,如何避免:

    首先引进

    [DllImport("urlmon.dll", CharSet = CharSet.Auto, SetLastError = true)]
              static extern Int32 URLDownloadToFile(
                  [MarshalAs(UnmanagedType.IUnknown)] object pCaller,
                  [MarshalAs(UnmanagedType.LPWStr)] string szURL,
                  [MarshalAs(UnmanagedType.LPWStr)] string szFileName,
                  Int32 dwReserved,
                  IntPtr lpfnCB);
    再添加  
    this.WebBrowser.Navigating += WebBrowser_Navigating;

    void WebBrowser_Navigating(object sender, WebBrowserNavigatingEventArgs e)
    {
               //设置下载条件
    if (e.Url != null && e.Url.AbsolutePath.IndexOf("/V1/Delivery/Download") > -1) { try { if (Citation.IsValid) { UIManager.ProgressMessageHandler(this, new UIEventArgs { Message = "Downloading "+ e.Url.Segments[e.Url.Segments.Length - 1]});                      string fullname = Path.Combine(pdfSavePath_, e.Url.Segments[e.Url.Segments.Length - 1]);                      
                         //在这替换“下载提示框”,并自定义下载
                         
    int response = URLDownloadToFile(null, e.Url.AbsoluteUri, fullname, 0, IntPtr.Zero); if (response == 0) { Citation.IsDownloaded = true; UIManager.ProgressMessageHandler(this, new UIEventArgs { Message = Citation.Name + " has downloaded." }); } } } catch { } finally {
                     //取消“下载提示框”,不会再提示用户 e.Cancel
    = true; } } }


                     
  • 相关阅读:
    常用模块介绍
    正则表达式/re模块
    模块简介/模块的导入/模块的查找顺序/绝对导入和相对导入/软件开发目录规范
    迭代器/for循环本质/生成器/常用内置方法
    函数递归/二分法/列表,字典生成式/三元表达式/匿名函数/内置函数
    闭包函数/装饰器
    函数对象/函数的嵌套定义与调用/名称空间和作用域
    初识函数
    文件处理/光标移动/实时检测
    7-5字符编码和文件处理
  • 原文地址:https://www.cnblogs.com/yipeng-yu/p/4901158.html
Copyright © 2011-2022 走看看