本帖最后由 Pojie1999.0909 于 2021-2-20 21:28 编辑
管理你好,如有违规,还请见谅!
vs2019编写的c# winform应用程序,.net framework 4.7 框架,引用了selenium和hzh_control动态库,前者用于模拟浏览器操作,后者用于UI
虽说用户体验不太好,但可以用它来批量下载音乐(一次最多下载30首,根据当前html页table标签有多少行决定)...
使用方法:
0.查看自己的edge浏览器版本,如下:
1.下载edge浏览器对应版本的WebDriver,网址:https://developer.microsoft.com/en-us/microsoft-edge/tools/webdriver/#downloads
2.将下载好的WebDriver放到目录 C:\WebDriver\bin 下面并添加到Path环境变量,将文件名修改为 MicrosoftWebDriver.exe,如下:
2
3.打开程序,输入网页地址,点击搜索,选中要下载的歌曲,点击下载,自动保存到 D:\ 盘根目录下
百度网盘:
复制这段内容后打开百度网盘App,操作更方便哦。 链接:https://pan.baidu.com/s/1affxLIHk36O13jwTTpe97w 提取码:p1f0--来自百度网盘超级会员V5的分享
求大佬们不要吝啬你们的【热心值】!求点赞、投币!我想升升级,多谢!
截图:
1
=====================================================
C# 程序很好反编译,感兴趣的朋友可以下载来看看,建议没有必要看,很简单,大佬请忽略...
以下是全部代码:
[C#] 纯文本查看 复制代码 using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using HZH_Controls.Forms;
using HZH_Controls.Controls;
using OpenQA.Selenium;
using OpenQA.Selenium.Edge;
using System.IO;
using System.Net;
using System.Threading;
namespace BabyMusicDownloader
{
public partial class Form1 : FrmWithTitle
{
public Form1()
{
InitializeComponent();
m_SyncContext = SynchronizationContext.Current;
this.Title = "【吾爱破解论坛】 BabyMusicDownloadApp - by Pojie1999.0909";
this.IsShowCloseBtn = true;
List<DataGridViewColumnEntity> lstCulumns = new List<DataGridViewColumnEntity>();
lstCulumns.Add(new DataGridViewColumnEntity() { DataField = "Title", HeadText = "标题", Width = 40, WidthType = SizeType.Percent });
lstCulumns.Add(new DataGridViewColumnEntity() { DataField = "Href", HeadText = "链接", Width = 40, WidthType = SizeType.Percent });
lstCulumns.Add(new DataGridViewColumnEntity()
{
DataField = "State",
HeadText = "状态",
Width = 20,
WidthType = SizeType.Percent,
Format = (a) => { return Convert.ToInt32(a) == 0 ? "等待下载" : Convert.ToInt32(a) == 1 ? "下载完成" : "歌曲已存在"; }
});
this.ucDataGridView1.Columns = lstCulumns;
this.ucDataGridView1.IsShowCheckBox = true;
}
private void ucBtnExt1_BtnClick(object sender, EventArgs e)
{
lstSource.Clear();
driver.Navigate().GoToUrl(ucTextBoxEx1.InputText);
IWebElement table = driver.FindElement(By.ClassName("list_musiclist"));
IList<IWebElement> redlines = table.FindElements(By.ClassName("redline"));
foreach (IWebElement item in redlines)
{
string song = item.FindElement(By.TagName("a")).Text;
lstSource.Add(new SongObj { Title = song + ".mp4", Href = item.FindElement(By.TagName("a")).GetAttribute("href"), State = "0" });
}
ucDataGridView1.DataSource = lstSource;
}
private void ucBtnExt2_BtnClick(object sender, EventArgs e)
{
Task.Run(() =>
{
ThreadProcSafePost();
});
}
private void Form1_FormClosed(object sender, FormClosedEventArgs e)
{
driver.Close();
driver.Quit();
}
private void ThreadProcSafePost()
{
if (ucDataGridView1.SelectRows.Count < 1)
{
FrmDialog.ShowDialog(this, "请选择至少一条记录!", "提示");
}
else
{
foreach (var item in ucDataGridView1.SelectRows)
{
string title = ((SongObj)item.DataSource).Title;
string href = ((SongObj)item.DataSource).Href;
driver.Navigate().GoToUrl(href);
IJavaScriptExecutor js = (IJavaScriptExecutor)driver;
string truthUrl = js.ExecuteScript("return playurl2").ToString();
string fileName = rootPath + title;
if (!File.Exists(fileName))
{
WebClient client = new WebClient();
client.DownloadFile(truthUrl, fileName);
lstSource.Where(x => x.Title == title && x.Href == href).ToList()[0].State = "1";
}
else
{
lstSource.Where(x => x.Title == title && x.Href == href).ToList()[0].State = "2";
}
m_SyncContext.Post(SetDataGridViewSafePost, null);
}
}
}
private void SetDataGridViewSafePost(object state)
{
this.ucDataGridView1.ReloadSource();
}
IWebDriver driver = new EdgeDriver();
const string domain = "http://www.bbdj.com/";
const string rootPath = @"D:\";
List<SongObj> lstSource = new List<SongObj>();
SynchronizationContext m_SyncContext = null;
}
public class SongObj
{
public string Title { get; set; }
public string Href { get; set; }
public string State { get; set; }
}
}
|