控制台版本,winform更简单


static string desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop)+"/";

[STAThread]
static void Main( string[ ] args )
{
//注册事件
    webBrowser.DocumentCompleted += WebBrowser_DocumentCompleted;

   webBrowser.Navigate( "https://helloareyouok.lanzous.com/i94vape" );

    Application.Run( );   
}

//事件调用
private static void WebBrowser_DocumentCompleted( object sender , WebBrowserDocumentCompletedEventArgs e )
{
    try
    {
MessageBox.Show( "加载成功" );

        WebBrowser webBrowser = (WebBrowser)sender;
        var 文件名 = webBrowser.Document.Title.Replace(" - 蓝奏云", "");
       
        // /html/body/div[2]/a
        HtmlElement a = webBrowser.Document.Window.Frames[0].Document.GetElementsByTagName("div")[1].FirstChild;
        //foreach( HtmlWindow item in webBrowser.Document.Window.Frames )
        //{
        //    var go = item.Document.GetElementById("go");
        //    a = go.FirstChild ?? null;
        //}
        var href = a.GetAttribute("href");
        MessageBox.Show( href );

        httpWebRequest = HttpWebRequest.CreateHttp( href );
      
        httpWebRequest.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8";

        var uri=httpWebRequest.GetResponse().ResponseUri.ToString();

        Console.WriteLine( 文件名 );
        Console.WriteLine( uri );

        if( File.Exists( desktopPath + 文件名 ) )
        {
            File.Delete( desktopPath + 文件名 );
        }
        new WebClient().DownloadFile( uri , desktopPath + 文件名 );

    }
    finally
    {
        webBrowser.DocumentCompleted -= WebBrowser_DocumentCompleted;
    }
}
 

最新文章

  1. C# WinForm实现Windows 7 Aero磨砂玻璃效果
  2. Windows 设置Mongodb
  3. Eclipse中web项目部署至Tomcat步骤
  4. Mina、Netty、Twisted一起学(十):线程模型
  5. NIS 报错No such map passwd.byname. Reason: Can't bind to server which serves this domain
  6. Android 模拟器 获得 root权限
  7. 在bash shell中使用getfattr查看文件扩展属性
  8. easy ui tabs 顶部绑定事件
  9. 【错误总结之(一)】error LNK2038: 检測到“_ITERATOR_DEBUG_LEVEL”的不匹配项: 值“0”不匹配值“2”
  10. 痞子衡嵌入式:恩智浦LPC系列MCU开发那些事 - 索引
  11. webpack4 系列教程(七): SCSS提取和懒加载
  12. win10 大文件 安卓android studio修改 汉化
  13. 用OpenGL实现动态的立体时钟
  14. java将字符串根据空格进行分割,使用split方法
  15. BugkuCTF ---游戏过关 writeup
  16. 微信小程序—day01
  17. Ionic实战五:ionic图表源码基于highcharts
  18. 设置PDF文件默认缩放比例
  19. Linux下which命令使用详解(转)
  20. 110.Balanced Binary Tree---《剑指offer》面试39

热门文章

  1. 浅谈JS输出中的“+”作用问题
  2. mi
  3. Rocky linux command-1
  4. SICP 笔记:环境配置
  5. Jmeter性能测试入门到项目实战03
  6. java技术系列(四) 泛型
  7. 嵌入式Qt中实现串口读取的事件驱动方法
  8. 2363. 合并相似的物品 (Easy)
  9. mariadb数据库用户管理(创建、赋权、)
  10. 【C学习笔记】day2-3 求10 个整数中最大值