0 votes
in VBA by Beginner (5 points)

Hey folks,

 

I am having trouble with this particular tutorial from wellsr: https://wellsr.com/vba/2018/excel/vba-web-scraping-with-getelementsbytagname/

I am about midway through the article when it asks me to put a breakpoint in my code and use 

?table_data.Item(0).innertext in my immediate window to show the text of the first item in the table_data collection object. 

 

 I have inserted my breakpoint at  the line of Table_data = webpage.getElementsByTagName("tr")

Here is where I run into an error 424 "Object Required", I'm not understanding why this error is occuring, can someone point me in the right direction here?



Sub Scrapper()

Dim ie As InternetExplorer
Dim webpage As HTMLdocument
Set ie = New InternetExplorer


ie.Visible = True
ie.addressbar = False


ie.navigate ("https://en.wikipedia.org/wiki/List_of_countries_and_dependencies_by_population")
Do While ie.Busy = True
Loop

Set webpage = ie.document
Table_data = webpage.getElementsByTagName("tr")




End Sub


 

by Super Expert (3.2k points)
+1

When you right-click your table_data and select "Add to Watch" and run your macro again, is the "Value" showing up as "Nothing" in the Watch Window?

This isn't related to your issue, but it appears the Wiki changed formats since this tutorial was posted. Once we get this issue resolved for you and you get to the final scrape_wikipedia_pop_data macro at the bottom, you'll eventually need to change 

Set mtbl = webpage.getElementsByTagName("Table")(1)

to

Set mtbl = webpage.getElementsByTagName("Table")(0)

 

by Expert (911 points)
+1
This illustrates the frustration with "web scraping": The web source keeps changing.
by Beginner (5 points)
Currently when I run the program and watch that value, it is listed as "out of context"
by Super Expert (3.2k points)

It should only show "out of context" when the program isn't running. You'll need to add breakpoint (F9) on any line after Table_data = webpage.getElementsByTagName("tr") and run the code to that breakpoint.

While you're at it, what operating system are you using and what version of Excel?

1 Answer

+1 vote
by Beginner (26 points)
selected by
 
Best answer

The error occurs because the result of

webpage.getElementsByTagName("tr")

is an object. You need to use set , as in

Set Table_Data = webpage.getElementsByTagName("tr")

Good luck,

MM

by Super Expert (3.2k points)
Doh! I've looked at this tutorial so many times and I never caught that typo.Thanks for pointing it out!

Welcome to wellsr Q&A
Ask any questions you have about VBA and Python and our community will help answer them. wellsr Q&A is the standalone question and answer platform for wellsr.com. If you have a question about one of our specific tutorials, please include a link back to the tutorial.

Getting Started
Register
VBA Cheat Sheets (On Sale Now)

Looking for something else? Hire our team directly through ourVBA Help page, instead.

For more programming tips visit the VBA Tutorials Blog and the Python Tutorials Blog.

...