كود :
Imports System.Text.RegularExpressions
Imports System.Net
Imports System.Text
Public Class Form1
Dim lst As New List(Of String)
Private Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
Dim url As String = "http://www.exalead.fr/search/web/results/?q=algerie"
Dim wc As New WebClient
wc.Encoding = System.Text.Encoding.UTF8
Dim html As String = wc.DownloadString(url)
Dim doc As New HtmlAgilityPack.HtmlDocument
doc.LoadHtml(html)
For Each n As HtmlAgilityPack.HtmlNode In doc.DocumentNode.SelectNodes("//div[@class='media-body']/a[@href]")
ListBox1.Items.Add(n.InnerText)
Next
End Sub
End Class
كود :
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