How to get Value by VBA from Source code

ng999

New Member
Joined
Jan 20, 2020
Messages
1
Office Version
  1. 2013
Platform
  1. Windows
I'm trying to use VBA for web scrapping (★ Dream Catcher Home Stay, Cochin, India) and get numerical value for "b_hotel_id" line in the code below

Code:
<td class="line-number" value="568"></td>

<td class="line-content">b_hotel_id: '554615',</td>

but I don't know how to refer to it, as there is no ID or TAG. This data is hidden from website and visible only in the source code.

I was trying to fetch the data using this VBA code:

VBA Code:
Public Sub GetValueFromBrowser()

    Dim ie As Object

    Dim url As String

    Dim bkid As String


    url = "https://www.booking.com/hotel/in/dream-catcher-home-stay.en-gb.html"

    Set ie = CreateObject("InternetExplorer.Application")


    With ie

      .Visible = 0

      .navigate url

       While .Busy Or .readyState <> 4

         DoEvents
       Wend

    End With


    Dim Doc As HTMLDocument

    Set Doc = ie.document


    bkid = Trim(Doc.getElementsByName("b_hotel_id:")(0).Value)

    Range("A1").Value = bkid

End Sub

Could you please help?
 

Attachments

  • bhotid.PNG
    bhotid.PNG
    12.1 KB · Views: 19

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
Quick and dirty and assumes that there are always 6 digits. You can easily adapt it if that's not the case.

VBA Code:
bkid = left(split(Doc.body.innerHTML,"booking.env.b_hotel_id = '")(1),6)

Note the apostrophe and then quotes: "booking.env.b_hotel_id = '"
 
Upvote 0

Forum statistics

Threads
1,224,813
Messages
6,181,107
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top