"GET" HTML values from the 'current URL' aka "active" tab in internet explore

Excelody

New Member
Joined
Dec 28, 2021
Messages
5
Office Version
  1. 2016
Platform
  1. Windows
I have an excel code which scrapes information from a web-page. In this example I've used "britannica.com/animal/leopard"

When the code is played in VBA, it returns the following values from the <H1> html tags:
  • "Distribution"
  • "Natural history"

However I want to "GET" these values from the 'current URL' aka "active" tab in internet explore

So rather than saying "GET" values from this URL

VBA Code:
website = "https://www.britannica.com/animal/leopard"

I want it to say "GET" these values from the current "active" tab in internet explore/ edge for example:

VBA Code:
website = CurrentActiveIETab

VBA Code:
Sub Get_Web_Data()

Dim request As Object
Dim response As String
Dim html As New HTMLDocument
Dim website As String
Dim price As Variant

' Website to go to.
website = "https://www.britannica.com/animal/leopard"


' Create the object that will make the webpage request.
Set request = CreateObject("MSXML2.XMLHTTP")

' Where to go and how to go there - probably don't need to change this.
request.Open "GET", website, False
' Get fresh data.
request.setRequestHeader "If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT"
' Send the request for the webpage.
request.send

' Get the webpage response data into a variable.
response = StrConv(request.responseBody, vbUnicode)

' Put the webpage into an html object to make data references easier.
html.body.innerHTML = response

' Get the price from the specified element on the page.
price = html.getElementsByClassName("h1")(0).innerText
test2 = html.getElementsByClassName("h1")(1).innerText

' Output the price into a message box.
Range("A1") = price
Range("A2") = test2

End Sub
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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