IE Automation - Run-Time Error 91

kikiwi

New Member
Joined
Jun 6, 2015
Messages
1
Hi,

I am trying to extract data through VBA from every search result from the website 微博搜索 - illuma - 微博

I am using Excel 2013 and IE11, but during execution, when it comes to the third feed, the run-time error 91 appears, saying 'object variable or with block variable not set'. I have been trying other methods to extract data, like using the following code:
ThisWorkbook.Sheets("SearchResult").Cells(i, 1) = feed.Item(1).Children(1).Children(1).Children(1).Children(1).Children(3).Children(2).Children(1).Title

However, the same error appears, and apparently, somewhere along the say, one of those 'childrens' are not appearing in the 'feed' variable in Excel. I have been stuck for over a week, and anyone one trying to help me getting out of this mess would be greatly appreciated. Thanks!

<code>
'To extract search result from Weibo
Sub Extraction()

Dim IE As SHDocVw.InternetExplorer
Dim keyword As String
Dim dateinput As Boolean
Dim datefrom As String
Dim dateto As String
Dim feed As IHTMLElementCollection
Dim html As HTMLDivElement
Dim i As Integer
Dim j As Integer

'set values of variables
keyword = ThisWorkbook.Sheets("Input").Cells(1, 3)
dateinput = ThisWorkbook.Sheets("Input").Cells(2, 3)
If dateinput Then
datefrom = ThisWorkbook.Sheets("Input").Cells(3, 3)
dateto = ThisWorkbook.Sheets("Input").Cells(4, 3)
End If

Set IE = CreateObject("InternetExplorer.Application")
IE.Visible = True
If dateinput Then
IE.Navigate "http://s.weibo.com/weibo/" & keyword & "&typeall=1&suball=1&timescope=custom:" & datefrom & ":" & dateto & "&page=1"
Else
IE.Navigate "http://s.weibo.com/weibo/" & keyword
End If

wait IE

waitseconds 2

Set html = IE.document.getElementById("pl_weibo_direct")
Set feed = html.getElementsByClassName("WB_cardwrap S_bg2 clearfix")

Dim temp As HTMLDivElement
i = 2
'For Each feed In IE.Document.getElementById("pl_weibo_direct").getElementsByTagName("div")
For j = 1 To feed.Length
ThisWorkbook.Sheets("SearchResult").Cells(i, 2) = feed.Item(j).innerHTML
i = i + 1
Next j




End Sub
'wait for the IE to load
Function wait(obj)
Do Until obj.readyState = 4: DoEvents: Loop
Do While obj.Busy: DoEvents: Loop
End Function
'wait for number of seconds
Function waitseconds(seconds As Double)
Dim future As Date
future = Now + seconds / 86400
Do Until Now >= future
DoEvents
Loop
End Function
</code>
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
i'd be tempted to build a trial for the third feed only and bring the function directly into the sub so you don't step out of the routine
 
Upvote 0

Forum statistics

Threads
1,214,945
Messages
6,122,395
Members
449,081
Latest member
JAMES KECULAH

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