Download and Parse Website


Imports System.Net.Http
Imports HtmlAgilityPack

Module Module2
    Sub Main()
        DownloadAndParseWebPage("https://example.com")
    End Sub

    Sub DownloadAndParseWebPage(url As String)
        Dim httpClient As New HttpClient()

        Try
            ' Download the webpage content
            Dim html As String = httpClient.GetStringAsync(url).Result

            ' Load the HTML into HtmlAgilityPack
            Dim htmlDoc As New HtmlDocument()
            htmlDoc.LoadHtml(html)

            ' Example: Extract all p tags
            ' Error message when no p tags
            For Each paragraph In htmlDoc.DocumentNode.SelectNodes("//p")
                Console.WriteLine(paragraph.InnerText)
            Next

            ' Example: Extract all li tags
            ' Error message when no li tags
            For Each paragraph In htmlDoc.DocumentNode.SelectNodes("//li")
                Console.WriteLine(paragraph.InnerText)
            Next

            ' You can add more parsing logic here to filter out wanted/unwanted sections
        Catch ex As Exception
            Console.WriteLine("Error: " & ex.Message)
        End Try
    End Sub
End Module

Download 'Download Parse Website.vb':

📥 Download download-parse-website.vb