Windows

Cross-platform

Quick start for console application

This guide shows how to start working with DotNetBrowser and embed it in a simple console application.

Before you begin make sure that your system meets software and hardware requirements.

1. Create a .NET console application

Open the Terminal or Command Line prompt, navigate to the necessary directory and run the following command:

dotnet new console -o Example.Console

The project will be created in the folder Example.Console.

2. Add DotNetBrowser package

Change directory to Example.Console and add the required package for your OS:

Windows:

dotnet add package DotNetBrowser

Linux x64:

dotnet add package DotNetBrowser.Linux-x64

Linux ARM64:

dotnet add package DotNetBrowser.Linux-arm64

macOS x64:

dotnet add package DotNetBrowser.macOS-x64

macOS ARM64:

dotnet add package DotNetBrowser.macOS-arm64

Cross-platform:

dotnet add package DotNetBrowser.CrossPlatform

3. Change source code

Insert the following code using any text editor into the Program.cs Program.vb file:

using System;
using DotNetBrowser.Browser;
using DotNetBrowser.Dom;
using DotNetBrowser.Engine;

EngineOptions.Builder builder = new EngineOptions.Builder();
// Uncomment the line below to specify your license key
// builder.LicenseKey = "your_license_key";

using (IEngine engine = EngineFactory.Create(builder.Build()))
{
    IBrowser browser = engine.CreateBrowser();
    browser.Navigation
        .LoadUrl("https://quotes.toscrape.com/random").Wait();

    IDocument document = browser.MainFrame.Document;
    string quote = document.GetElementByClassName("text")?.InnerText;
    string author = document.GetElementByClassName("author")?.InnerText;

    Console.WriteLine(quote);
    Console.WriteLine($"— {author}");
}
Imports DotNetBrowser.Browser
Imports DotNetBrowser.Engine

Module Program
    Sub Main(args() As String)
        Dim builder = new EngineOptions.Builder()
        ' Uncomment the line below to specify your license key
        ' builder.LicenseKey = "your_license_key"

        Using engine As IEngine = EngineFactory.Create(builder.Build())
            Dim browser As IBrowser = engine.CreateBrowser()

            browser.Navigation _
                    .LoadUrl("https://quotes.toscrape.com/random").Wait()

            Dim document = browser.MainFrame.Document
            Dim quote = document.GetElementByClassName("text")?.InnerText
            Dim author = document.GetElementByClassName("author")?.InnerText

            System.Console.WriteLine(quote)
            System.Console.WriteLine($"— {author}")
        End Using
    End Sub
End Module

4. Get trial license

To get a free 30-day trial license, fill in the web form and click the GET MY FREE TRIAL button. You will receive an email with the license key.

5. Add a license

To embed the license key into your project, copy the license key string from the email and insert it as shown below:

EngineOptions.Builder builder = new EngineOptions.Builder();
// Uncomment the line below to specify your license key
builder.LicenseKey = "your_license_key";
Dim builder = new EngineOptions.Builder()
' Uncomment the line below to specify your license key
builder.LicenseKey = "your_license_key"

For more information on license installation, refer to this article.

6. Run the application

To launch application, use:

dotnet run

Console

Go Top