我想制作一个小节目,这样我就可以快速轻松地收听这个电台了。
http://www.offradio.gr/player
问题是,我想不出有什么办法可以得到现在播放的曲目名称,制作人的名字和播放历史。
我想过从网站的原始源代码中提取特定的数据,但是源代码就像4000行代码--太多了,我无法处理。
有什么想法吗?
我正在使用和C#
发布于 2013-10-17 09:19:17
我知道这不是最好的方法,但它是一个起点,它起作用:
public Form1()
{
InitializeComponent();
webBrowser1.DocumentCompleted += webBrowser1_DocumentCompleted; // Subscribe event
webBrowser1.Navigate("http://www.offradio.gr/player"); // Navigate to radio stream
}
private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
/*
Look for the element containing the element with the track number
I've chosen this one because it has an ID means it's always the same div
*/
HtmlElement parent = webBrowser1.Document.GetElementById("show_info");
if (parent != null) // This event fires multiple times. Sometimes this element hasn't been created yet
{
/*
We know it's a childless node inside `#show_info`.
So let's just search for it.
*/
foreach (HtmlElement child in parent.GetElementsByTagName("span"))
{
if (child.Children.Count == 0) // Check if it has children
{
string title = child.InnerText; // The result
break;
}
}
}
}不幸的是,我不得不使用.NET函数,对于JS,我会使用一个更简单的方法:
document.querySelector('#show_info .field-content').innerText
更新:
我再给你个提示。
看看document.getElementById('show_info').innerText的输出。
你可以解析它,然后你就完成了!
希望它能帮上忙
https://stackoverflow.com/questions/19421693
复制相似问题