Constantly getting
Run-time error '-2147417848 (80010108)':
Automation error
The object invoked has disconnected from its clients
I'm messing around with HTML and trying to learn how to pull values from websites. For this test I'm opening my Stack Overflow profile and pulling my rep value to place in a cell. I have all my reference libraries enabled, but I continuously get this error.
Option Explicit
Sub GetTheValue()
Dim IE As InternetExplorer, retrievedvalue As Variant, oHTML_Element As IHTMLElement
Set IE = New InternetExplorerMedium
IE.Visible = True
IE.navigate "https://stackoverflow.com/users/7668613/dwirony"
Application.Wait (Now + TimeValue("0:00:05"))
For Each oHTML_Element In IE.Document.getelementsbyID("top-cards")
If oHTML_Element.classname = "g-col fl-none -rep" Then
retrievedvalue = oHTML_Element.InnerText
Exit For
End If
Next oHTML_Element
Workbooks("Book1").Worksheets("Sheet1").Range("A1").Value = retrievedvalue
End Sub
Error occurs on line
For Each oHTML_Element In IE.Document.getelementsbyID("top-cards")
Here's the snippet I'm trying to read from:
<div id="top-cards" class="g-row _gutters p-highlights">
<aside class="g-col g-column -card -reputation js-highlight-box-reputation">
<h1 class="g-col -title">Reputation</h1>
<div class="g-row -row-first">
<div class="g-col g-column">
<div class="g-row _gutters fl-none">
<span class="g-col fl-none -rep">897</span>