Wie komme ich an ein HtmlElement ohne diesen Urzeit-Webbrowser

  • VB.NET
  • .NET (FX) 4.5–4.8

Es gibt 2 Antworten in diesem Thema. Der letzte Beitrag () ist von Bartosz.

    Wie komme ich an ein HtmlElement ohne diesen Urzeit-Webbrowser

    Hallo, ich möchte an alle HtmlElemente herankommen, allerdings ohne den Webbrowser aus der Toolbox zu nutzen.

    Mit ihm habe ich mal folgenden Code gesehen

    VB.NET-Quellcode

    1. For Each Elem As HtmlElement In WebBrowser1.Document.All
    2. Dim GetAtt_String As String = Elem.GetAttribute("src")
    3. Dim imgsrc As String = GetAtt_String
    4. If GetAtt_String = "" Then
    5. Continue For
    6. Else
    7. '....

    Die URL ist gegeben.
    @ISliceUrPanties Danke dir! Eine Frage noch: Ich bekomme ich leider nicht hin, die ("src") Attribute herauszubekommen... Könntest du mir da helfen? Ein Beispiel bei Google ist schlimmer als das andere

    VB.NET-Quellcode

    1. Dim doc As HtmlAgilityPack.HtmlDocument = New HtmlAgilityPack.HtmlDocument()
    2. doc.Load(UrlString)
    3. Dim root As HtmlAgilityPack.HtmlNode = doc.DocumentNode
    4. Dim anchorTags As New List(Of String)
    5. For Each link As HtmlAgilityPack.HtmlNode In root.SelectNodes("//img")
    6. If link.HasAttributes() Then
    7. Debug.WriteLine("ja")
    8. End If
    9. Next



    Edit:

    VB.NET-Quellcode

    1. Dim doc As HtmlAgilityPack.HtmlDocument = New HtmlAgilityPack.HtmlDocument()
    2. doc.Load(UrlString)
    3. Dim root As HtmlAgilityPack.HtmlNode = doc.DocumentNode
    4. For Each link As HtmlAgilityPack.HtmlNode In root.SelectNodes("//img")
    5. If link.HasAttributes() Then
    6. Dim alle_Attribute As HtmlAgilityPack.HtmlAttributeCollection = link.Attributes
    7. For Each attr As HtmlAgilityPack.HtmlAttribute In alle_Attribute
    8. If attr.Name = "src" AndAlso (attr.Value.ToLower.EndsWith(".jpg") OrElse attr.Value.ToLower.EndsWith(".jpeg") OrElse attr.Value.ToLower.EndsWith(".bmp") OrElse attr.Value.ToLower.EndsWith(".png")) Then
    9. Download(attr.Value) 'meine Prozedur
    10. End If
    11. Next
    12. End If
    13. Next


    Dieser Beitrag wurde bereits 3 mal editiert, zuletzt von „Bartosz“ ()