سلام دوست عزیز
این کد رو یکی از دوستان توی گروه سی شارپ قرار دادن و راهنمایی ایشون هستش.البته کد زیر برای وی بی دات نت هستش
Imports System.IO
Imports System.Net
Imports System.Text.RegularExpressions
Public Class Form1
Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Load
textBox1.Text = "711783" ' Product ID (dkp-711783)
button1.Text = "Get"
End Sub
Private Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
Button1.Text = "Wait..."
Button1.Enabled = False
Application.DoEvents()
Dim url = "https://www.digikala.com/product/dkp-" & TextBox1.Text
Dim page = GetPage(url)
Dim classId = "c-product__seller-price-raw js-price-value"
Dim regex = New Regex("<div class=""" + classId + """>\s*(?<price>[^\<\s]*)\s*</div>", RegexOptions.IgnoreCase)
Dim match = regex.Match(page)
Label1.Text = IIf(match.Success, match.Groups("price").Value, "Not found!")
Button1.Text = "Get"
Button1.Enabled = True
End Sub
Private Function GetPage(ByVal url As String) As String
Try
Dim request = DirectCast(WebRequest.Create(url), HttpWebRequest)
With request
.CookieContainer = New CookieContainer
.Proxy = WebRequest.DefaultWebProxy
.UserAgent = "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36"
.ProtocolVersion = HttpVersion.Version10
.Accept = "*/*"
.ContentType = "text/html"
.ContentLength = 0
End With
Using response = DirectCast(request.GetResponse(), HttpWebResponse)
Dim stream = response.GetResponseStream()
If stream Is Nothing Then
Return String.Empty
End If
Using reader = New StreamReader(stream)
Return reader.ReadToEnd
End Using
End Using
Catch
Return ""
End Try
End Function
End Class
808080.jpg
یک لیبل و یک تکست باکس و یک باتن قرار بدین در فرمتون
موفق باشید