62,039
社区成员
发帖
与我相关
我的任务
分享
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Windows.Forms;
namespace ConsoleApplication1
{
class Program
{
[STAThread]
static void Main(string[] args)
{
WebBrowser wb = new WebBrowser();
wb.ScrollBarsEnabled = false;
wb.ScriptErrorsSuppressed = true;
wb.Navigate("http://yun.baidu.com/s/1pJJUOob");
while (wb.ReadyState != WebBrowserReadyState.Complete) { Application.DoEvents(); }
string html = wb.Document.Body.InnerHtml;
Console.WriteLine("分享:{0}", GetElementsByClassName(wb.Document, "sharecnt").GetElementsByTagName("a")[0].GetElementsByTagName("em")[0].InnerText);
Console.WriteLine("专辑:{0}", GetElementsByClassName(wb.Document, "albumcnt").GetElementsByTagName("a")[0].GetElementsByTagName("em")[0].InnerText);
Console.WriteLine("订阅:{0}", GetElementsByClassName(wb.Document, "followcnt").GetElementsByTagName("a")[0].GetElementsByTagName("em")[0].InnerText);
Console.WriteLine("粉丝:{0}", GetElementsByClassName(wb.Document, "fanscnt").GetElementsByTagName("a")[0].GetElementsByTagName("em")[0].InnerText);
Console.Read();
}
public static HtmlElement GetElementsByClassName(HtmlDocument doc, string className)
{
HtmlElementCollection collection = doc.All;
HtmlElement html = doc.CreateElement("");
foreach (HtmlElement he in collection)
{
if (he.GetAttribute("classname") == className)
{
html.AppendChild(he);
}
}
return html;
}
}
}