public static List<string> getLinkList(string url) { List<string> result = new List<string>(); try { NonDispBrowser ndb = new NonDispBrowser(); //2011/10/10 スクリプトエラーをもみけす ndb.ScriptErrorsSuppressed = true; //ナビゲート ndb.NavigateAndWait(url); HtmlDocument doc = ndb.Document; // リンク文字列とそのURLの列挙 foreach (HtmlElement et in doc.GetElementsByTagName("A")) { string href = et.GetAttribute("href"); // HREF属性の値 string text = et.InnerText; // リンク文字列 if (!string.IsNullOrEmpty(href) && !string.IsNullOrEmpty(text)) { result.Add(href); } } ndb.Dispose(); } catch { } return result; }
/// <summary> /// ウェブブラウザを取得する /// </summary> /// <param name="webBrowser"></param> /// <returns></returns> private bool getWebBrowser(ref NonDispBrowser webBrowser, string uri) { if (string.IsNullOrEmpty(uri) || uri.Equals("about:blank")) { return false; } if (!uri.StartsWith("http://")) { uri = "http://" + uri; } try { webBrowser.NavigateAndWait(uri); return true; } catch (UriFormatException) { return false; } }