Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

C# scrape html document

// install first using 
// Install-Package AngleSharp
// then
using System;
using AngleSharp;
using AngleSharp.Html.Parser;

class MyClass {
    static async Task Main() {
        //Use the default configuration for AngleSharp
        var config = Configuration.Default;

        //Create a new context for evaluating webpages with the given config
        var context = BrowsingContext.New(config);

        //Source to be parsed
        var source = "<h1>Some example source</h1><p>This is a paragraph element";

        //Create a virtual request to specify the document to load (here from our fixed string)
        var document = await context.OpenAsync(req => req.Content(source));

        //Do something with document like the following
        Console.WriteLine("Serializing the (original) document:");
        Console.WriteLine(document.DocumentElement.OuterHtml);

        var p = document.CreateElement("p");
        p.TextContent = "This is another paragraph.";

        Console.WriteLine("Inserting another element in the body ...");
        document.Body.AppendChild(p);

        Console.WriteLine("Serializing the document again:");
        Console.WriteLine(document.DocumentElement.OuterHtml);
    }
}
Comment

PREVIOUS NEXT
Code Example
Csharp :: c# picturebox cursor hand 
Csharp :: translate int to string with x 0 before c# 
Csharp :: Rotating an object in Unity usign Physics 
Csharp :: unity DOScale 
Csharp :: C# top down view movement 
Csharp :: c# external ip 
Csharp :: how to create a blazor client-side application in a command-line interface 
Csharp :: unity collision.impulse 
Csharp :: how to make a character jump c# 
Csharp :: how to know pm or am C# 
Csharp :: Getting the text from a drop-down box 
Csharp :: get first number in string C# 
Csharp :: disable alt + f4 in c# forms 
Csharp :: c# enum to list of strings 
Csharp :: or operator in shell 
Csharp :: c# mock ref parameter 
Csharp :: load information with txt file to uwp c# 
Csharp :: 2d array 
Csharp :: c# resize multidimensional array 
Csharp :: tachyons 
Csharp :: c# async and await example 
Csharp :: escape chars for regex c# 
Csharp :: c# convert xml to list string 
Csharp :: How to execute script in C# 
Csharp :: ascii code c# char 
Csharp :: change a positive number to negative or a negative number to positive 
Csharp :: c# double 
Csharp :: c# sort array by value 
Csharp :: ioptions mock c# unittest 
Csharp :: jq map over array 
ADD CONTENT
Topic
Content
Source link
Name
5+6 =