تقييم الموضوع :
  • 0 أصوات - بمعدل 0
  • 1
  • 2
  • 3
  • 4
  • 5
[VB.NET] مشكلة في استخراج روابط هذه الصفحة بال HtmlAgilityPack
#2
استخدم
كود :
Imports System.IO
Imports System.Net
Imports System.Text
Public Class Form1

    Private Function Extractlinks(ByVal Asec As String) _
            As List(Of String)
        Dim links As New List(Of String)
        Dim startSquence As String = "<a href="""
        Dim endsSquence As String = """"
        Asec = Asec.ToArray
        'Code : Security Alshaab
        While Asec.IndexOf("<a href") <> -1
            Dim start As Integer = Asec.IndexOf _
                                   (startSquence) + startSquence.Length
            Dim [end] As Integer = Asec.IndexOf _
                (endsSquence, start)
            If [end] > start Then
                Dim link As String = Asec.Substring _
                                     (start, [end] - start)
                If link <> String.Empty Then
                    If Not link.StartsWith("http://") Then
                        link = "../" & link
                    End If
                    links.Add(link)
                End If
            End If
            Asec = Asec.Substring _
            ([end] + endsSquence.Length)
        End While
        Return links
    End Function

    Private Function Downloaddata(ByVal url As String) As String
        Dim Security As Byte() = New Byte(-1) {}
        Try
            Dim req As WebRequest = WebRequest.Create(url)
            Dim response As WebResponse = req.GetResponse
            Dim Alshaab As Stream = response.GetResponseStream
            Dim buffer As Byte() = New Byte(1023) {}
            Dim datalength As Integer = CInt(response.ContentLength)
            Dim Ali As New MemoryStream
            While True
                Dim bytesread As Integer = _
                    Alshaab.Read(buffer, 0, buffer.Length)
                Application.DoEvents()
                If bytesread = 0 Then
                    Exit While
                Else
                    Ali.Write(buffer, 0, bytesread)

                End If
            End While
          
            Security = Ali.ToArray
            Alshaab.Close()
            Ali.Close()
        Catch ex As Exception
            MsgBox("قم بوضع رابط صحيح")
        End Try
        Return ASCIIEncoding.ASCII.GetString(Security)
    End Function
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    End Sub

    Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
      


    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim AmroshSecurity As String = Downloaddata(TextBox1.Text)
        ListBox1.Items.AddRange(Extractlinks(AmroshSecurity).ToArray)
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        ListBox1.Items.Clear()
        TextBox1.Text = "https://"
    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        Me.Hide()
        Form2.Show()
    End Sub
End Class
هم يسرقون والقانون كتب لنا...
[صورة مرفقة: 2uWPM9L]

الرد }}}
تم الشكر بواسطة: ابو روضة


الردود في هذا الموضوع
RE: مشكلة في استخراج روابط هذه الصفحة بال HtmlAgilityPack - بواسطة DK-x - 13-10-18, 03:32 PM


التنقل السريع :


يقوم بقرائة الموضوع: