private static void heroImage() { string link= "http://dota.sgamer.com/hero/"; HtmlHelp htmlhelp = new HtmlHelp(); string htmlStr=htmlhelp.DownloadPage(link); string heropart = htmlhelp.GetUniqTag(htmlStr, "div", "class=\"BG_Block\""); List<string> allheros = htmlhelp.GetTagCollectByCharacter(heropart, "li", ""); int i=0; foreach (var item in allheros) { i++; Console.WriteLine(i); if (i ==17) { Hero hero = new Hero(item); jiengImage(hero.Href); } //string gif = hero.Src; //int start = gif.LastIndexOf('/'); //int length = gif.Length - start; //string name = gif.Substring(start + 1); //try //{ // System.Drawing.Image imgFile = System.Drawing.Image.FromFile(@"D:\Dota\Heros\" + name.Substring(0, name.Length - 4) + ".png"); // imgFile.Save(@"D:\Dota\Heros1\" + name.Substring(0, name.Length - 4) + ".png", System.Drawing.Imaging.ImageFormat.Png); //} //catch //{ // Console.WriteLine(gif); //} //// string name1 = " /Avatar/" + name.Substring(0, name.Length - 4) + ".png"; ////htmlhelp.DownloadImgae(@"D:\Dota\Heros\" + name.Substring(0, name.Length - 4) + ".png", gif); //Console.WriteLine(name.Substring(0, name.Length - 4) + ".png"); } Console.WriteLine("end...."); Console.ReadLine(); }
public void DownloadPage() { string link = "http://dota.sgamer.com/hero/"; string deskfile = "3.txt"; FileStream afile = new FileStream(@"D:\Dota\" + deskfile, FileMode.Create); StreamWriter writer = new StreamWriter(afile); HtmlHelp htmlhelp = new HtmlHelp(); string dotapage = htmlhelp.DownloadPage(link); string heropart = htmlhelp.GetUniqTag(dotapage, "div", "class=\"BG_Block\""); List<string> allheros = htmlhelp.GetTagCollectByCharacter(heropart, "li", ""); // get all heros data foreach (var item in allheros) { Hero hero = new Hero(item); writer.WriteLine(hero.Alt + ";" + hero.Src + ";" + hero.Href); } if (writer != null) { writer.Close(); } if (afile != null) { afile.Close(); } Console.WriteLine("end..."); Console.ReadLine(); }