Scraping HTML Website Text that doesn't have a Tag

knute_gis

New Member
Joined
Jul 5, 2019
Messages
7
I have figure out how to get all of the data from this website query except for the text I really need.

Is there a way to get the text "exhaustion" and "Replace Pole" from the HTML?
I have tried children and innertext but I cant get it to work. -Thanks, Knute

image001.jpg


image002.jpg
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
Will this help?
HTML:
<html>
<body>
<div>
<script></script>
<i># records: 1</i>
<br />
<br />
<i>critical_steps:</i>
exhaustion
<br />
<i>job_type:</i>
Replace Pole<br />
<br />
</div>
</body>
</html>
VBA Code:
Sub knute_gis()

Dim myurl As String
Dim iElement, iElements As Variant
Dim IE As MSXML2.XMLHTTP60
Dim HTMLDoc As MSHTML.HTMLDocument
Dim HTMLBody As MSHTML.HTMLBody
Dim i As Long
Dim sht As Worksheet

Set IE = New MSXML2.XMLHTTP60
Set HTMLDoc = New MSHTML.HTMLDocument
Set HTMLBody = HTMLDoc.body

myurl = "URL to Query here!"
IE.Open "GET", myurl, False
IE.send

On Error Resume Next

HTMLDoc.body.innerHTML = IE.responseText
Flat = False
i = 0

Set iElements = HTMLDoc.getElementsByTagName("i")
For Each iElement In iElements
  i = i + 1
  ThisWorkbook.Sheets("Sheet1").Cells(i, 1) = iElement.innerText
  ThisWorkbook.Sheets("Sheet1").Cells(i, 2) = iElement.NextSibling.NodeValue
Next

End Sub

Book1
AB
1# records: 1
2critical_steps: exhaustion
3job_type: Replace Pole
Sheet1
 
Upvote 0
That is awesome, thank you so much for taking the time to do that!
I have seen "NodeValue" but wasn't sure if that would work.

I will give it a try tomorrow and let you know how it goes.
 
Upvote 0
Very welcome! Glad to help! Thanks for updating us! :)
 
Upvote 0

Forum statistics

Threads
1,216,140
Messages
6,129,105
Members
449,486
Latest member
malcolmlyle

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