Help with Web Scraping VBA

ck248

New Member
Joined
Dec 6, 2017
Messages
5
Looking for some help. I'm using this code right now to scrape the innertext of all <li>s on a webpage where the class name is "error' (e.g. <li class="error">, within a DIV tag.

However it doesn't work when there is no DIV tag on a page. Can anyone help me to do the same thing, but without there being a DIV on the page and so that if there is a tag with <li class="error">XYZ"</li>, it will extract XYZ as the innertext.

Set Divelements = htm.getElementsByTagName("li")
For Each divElement In Divelements
If InStr(1, divElement.className, "error") Then
Debug.Print divElement.InnerText

t1 = t
For Each El In divElement.ParentNode.getElementsByTagName("p")
o.Cells(t1, 2) = El.InnerText
t1 = t1 + 1
Next El

t = t1

Exit For 'only the first loop
End If

Next
i = i + 1
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
First post should read:

Looking for some help. I'm using this code right now to scrape the innertext of all s on a webpage where the class name is "error' (e.g.
, within a DIV tag. However it doesn't work when there is no DIV tag on a page. Can anyone help me to do the same thing, but without there being a DIV on the page? So if there is a tag with
XYZ"
, it will extract XYZ as the innertext.
 
Upvote 0
Trying agin to show the HTML tags:

Looking for some help. I'm using this code right now to scrape the innertext of all [LI]s on a webpage where the class name is "error' (e.g. [LI class="error"], within a DIV tag. However it doesn't work when there is no DIV tag on a page. Can anyone help me to do the same thing, but without there being a DIV on the page? So if there is a tag with [li class="error"]XYZ"[/li], it will extract XYZ as the innertext.
 
Upvote 0

Forum statistics

Threads
1,223,889
Messages
6,175,223
Members
452,620
Latest member
dsubash

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