How to get Value by VBA from Source code

ng999

New Member
Joined
Jan 20, 2020
Messages
1
Office Version
2013
Platform
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

Some videos you may like

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.

dataluver

Board Regular
Joined
Jan 17, 2020
Messages
198
Office Version
365
Platform
Windows
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 = '"
 

Watch MrExcel Video

Forum statistics

Threads
1,099,491
Messages
5,468,926
Members
406,620
Latest member
Gitani123

This Week's Hot Topics

Top