Skip to content

Instantly share code, notes, and snippets.

@vainolo
Last active May 6, 2020 20:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vainolo/9922ef7fb21fb340555759258c3846aa to your computer and use it in GitHub Desktop.
Save vainolo/9922ef7fb21fb340555759258c3846aa to your computer and use it in GitHub Desktop.
public static void Scrape()
{
var scraper = new HtmlWeb();
var page = scraper.Load("https://vainolo.z14.web.core.windows.net/WebScraping.html");
var techniquesTitle = page.GetElementbyId("Techniques");
var currNode = techniquesTitle.ParentNode.NextSibling;
while(currNode.Name != "h2")
{
if(currNode.GetClasses().Contains("mw-headline"))
{
var headline = currNode.InnerText;
Console.WriteLine(headline);
}
if(currNode.HasChildNodes)
{
currNode = currNode.FirstChild;
}
else if(currNode == currNode.ParentNode.LastChild)
{
while(currNode.ParentNode.NextSibling == null)
{
currNode = currNode.ParentNode;
}
currNode = currNode.ParentNode.NextSibling;
}
else
{
currNode = currNode.NextSibling;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment