How to use Regex.Match to Get Some values From Class with same name from a webpage ?

  • Thread starter Thread starter Mostafa Salaheldien
  • Start date Start date
M

Mostafa Salaheldien

Guest
Hello every one,

I have an issue

in my work I have to update all the details to our customers on Web-page application asp.net

all i did i saved the page CTRL + s to make a software at my home to get this classes values i used REGEX its worked Like sharp but, once i tried to test this software at my work its coming back without any values why ?

webpage code

<div class="res-detail-card">
<div class="col-sm-4 res-detail col-3__print">
<div class="row">
<div class="col-xs-7 col-sm-12 col-12__print">
<div class="bks-item">
<span class="res-details-label bui_font_caption">Check-in:</span>
<div class="bui_font_display_one">
Tue 7 Apr 2020
</div>
</div>

<div class="bks-item">
<span class="res-details-label bui_font_caption">Check-out:</span>
<div class="bui_font_display_one">
Wed 8 Apr 2020
</div>
</div>

<div class="bks-item">
<span class="res-details-label bui_font_caption">Length of stay:</span>
<div class="bui_font_body">1 night</div>
</div>
</div>

<div class="col-xs-5 col-sm-12 col-12__print">
<div class="bks-item">
<span class="res-details-label bui_font_caption">Total guests:</span>
<span class="bui_font_body">
2
</span>
</div>

<div class="bks-item">
<span class="res-details-label bui_font_caption">Total rooms:</span>
<div class="bui_font_body">1</div>
</div>
</div>
</div> <!-- .row -->



this is my code

i just use a Webbrowser control

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
WebBrowser1.Document.Write(IO.File.ReadAllText("test.html"))

End Sub
and to get values from classes i used


Dim html = WebBrowser1.DocumentText
Dim coll As MatchCollection = Regex.Matches(html, "<div class=""bks-item"">.+?</div>", RegexOptions.Singleline)
Dim CheckIn, CheckOut, LengthOfStay, TotalGuests, TotalRooms, Guestname As String
For Each mt As Match In coll
If mt.Value.Contains("Check-in:") Then
CheckIn = Regex.Match(mt.Value, "<div class=""bui_font_display_one"">(.+?)</div>", RegexOptions.Singleline).Groups(1).Value.Trim
TextBox1.Text = CheckIn
End If

If mt.Value.Contains("Check-out:") Then
CheckOut = Regex.Match(mt.Value, "<div class=""bui_font_display_one"">(.+?)</div>", RegexOptions.Singleline).Groups(1).Value.Trim
TextBox2.Text = CheckOut
End If

If mt.Value.Contains("Length of stay:") Then
LengthOfStay = Regex.Match(mt.Value, "<div class=""bui_font_body"">(.+?)</div>", RegexOptions.Singleline).Groups(1).Value.Trim
TextBox3.Text = LengthOfStay
End If
If mt.Value.Contains("Total guests:") Then
TotalGuests = Regex.Match(mt.Value, "<span class=""bui_font_body"">(.+?)</span>", RegexOptions.Singleline).Groups(1).Value.Trim
TextBox4.Text = TotalGuests
End If

If mt.Value.Contains("Total rooms:") Then
TotalRooms = Regex.Match(mt.Value, "<div class=""bui_font_body"">(.+?)</div>", RegexOptions.Singleline).Groups(1).Value.Trim
TextBox5.Text = TotalRooms
End If

Next

Continue reading...
 
Back
Top