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