Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>If this is a console application, then it will not work since the console application doesn't have a message pump (which is required for the <code>WebBrowser</code> to process messages).</strong></p> <p><strong>If you run this in a Windows Forms application</strong>, then you should handle the <code>DocumentCompleted</code> event:</p> <pre><code>WebBrowser browserEmulator = new WebBrowser(); browserEmulator.DocumentCompleted += OnDocumentCompleted; browserEmulator.Navigate(this.SiteRoot); </code></pre> <p>Then implement the method that handles the event:</p> <pre><code>private void OnDocCompleted(object sender, WebBrowserDocumentCompletedEventArgs e) { WebBrowser wb = sender as WebBrowser; if (wb.Document != null) { List&lt;string&gt; links = new List&lt;string&gt;(); foreach (HtmlElement element in wb.Document.GetElementsByTagName("a")) { links.Add(element.GetAttribute("href")); } foreach (string link in links) { Console.WriteLine(link); } } } </code></pre> <p><strong>If you want to run this in a console application</strong>, then you need to use a different method for downloading pages. I would recommend that you use the <a href="http://msdn.microsoft.com/en-us/library/system.net.webrequest.aspx" rel="nofollow noreferrer"><code>WebRequest</code></a>/<a href="http://msdn.microsoft.com/en-us/library/system.net.webresponse.aspx" rel="nofollow noreferrer"><code>WebResponse</code></a> and then use the <a href="http://htmlagilitypack.codeplex.com/" rel="nofollow noreferrer"><code>HtmlAgilityPack</code></a> to parse the HTML. The <code>HtmlAgilityPack</code> will generate an <code>HtmlDocument</code> for you and you can get the links from there.</p> <hr> <p>Additionally, if you're interested in learning more about building scalable web crawlers, then check out the following links:</p> <ul> <li><a href="https://stackoverflow.com/questions/1935148/how-to-crawl-billions-of-pages/7799090#7799090">How to crawl billions of pages?</a></li> <li><a href="https://stackoverflow.com/questions/5834808/designing-a-web-crawler/5834890#5834890">Designing a web crawler</a></li> </ul> <p>Good luck!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload