VBA Web Scrap

dushyantgupta111

New Member
Joined
Sep 16, 2015
Messages
4
Hi all,

I am trying to scrap list of VBA course items given at the right pane of the following link "www.tutorialspoint.com//vba/index.htm"

But I am unable to scrap list due to some error.

the code I have written is:

Code:
[COLOR=#E56717][B]Sub[/B][/COLOR] tutorailpointsscrap()
  [COLOR=#151B8D][B]Dim[/B][/COLOR] ie [COLOR=#151B8D][B]As[/B][/COLOR] InternetExplorer
   
  [COLOR=#151B8D][B]Set[/B][/COLOR] ie = [COLOR=#E56717][B]New[/B][/COLOR] InternetExplorer
   
  [COLOR=#8D38C9][B]With[/B][/COLOR] ie
  .navigate [COLOR=#800000]"https://www.tutorialspoint.com//vba/index.htm"[/COLOR]
  .Visible = [COLOR=#00C2FF][B]True[/B][/COLOR]
  [COLOR=#8D38C9][B]Do[/B][/COLOR] [COLOR=#8D38C9][B]While[/B][/COLOR] ie.readyState <> READYSTATE_COMPLETE
  [COLOR=#8D38C9][B]DoEvents[/B][/COLOR]
  [COLOR=#8D38C9][B]Loop[/B][/COLOR]
  [COLOR=#8D38C9][B]End[/B][/COLOR] [COLOR=#8D38C9][B]With[/B][/COLOR]
   
  [COLOR=#151B8D][B]Dim[/B][/COLOR] html [COLOR=#151B8D][B]As[/B][/COLOR] HTMLDocument
  [COLOR=#151B8D][B]Set[/B][/COLOR] html = ie.document
   
    
  [COLOR=#151B8D][B]Dim[/B][/COLOR] ele [COLOR=#151B8D][B]As[/B][/COLOR] IHTMLElement
   
  [COLOR=#151B8D][B]Dim[/B][/COLOR] lists [COLOR=#151B8D][B]As[/B][/COLOR] IHTMLElementCollection
  [COLOR=#151B8D][B]Dim[/B][/COLOR] row [COLOR=#151B8D][B]As[/B][/COLOR] [COLOR=#F660AB][B]Long[/B][/COLOR]
   
  [COLOR=#151B8D][B]Set[/B][/COLOR] ele = html.getElementsByClassName([COLOR=#800000]"nav nav-list primary left-menu"[/COLOR])
   
  [COLOR=#151B8D][B]Set[/B][/COLOR] lists = ele.getElementsByTagName([COLOR=#800000]"li"[/COLOR])
  row = 1

   
  [COLOR=#8D38C9][B]For[/B][/COLOR] [COLOR=#8D38C9][B]Each[/B][/COLOR] li [COLOR=#8D38C9][B]In[/B][/COLOR] lists
  Cells(row, 1) = li.innerText
  row = row + 1
  [COLOR=#8D38C9][B]Next[/B][/COLOR]
   
  ie.Quit

[COLOR=#8D38C9][B]End[/B][/COLOR] [COLOR=#E56717][B]Sub[/B][/COLOR]
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
Its on left pane.

Try this:


Code:
Sub tutorailpointsscrap()
  Dim ie As InternetExplorer
   
  Set ie = New InternetExplorer
   
  With ie
  .navigate "https://www.tutorialspoint.com//vba/index.htm"
  .Visible = True
  Do While ie.readyState <> READYSTATE_COMPLETE
  DoEvents
  Loop
  End With
   
  Dim html As HTMLDocument
  Set html = ie.document
   
    
  Dim ele As HTMLUListElement
   
  Dim lists As IHTMLElementCollection
  Dim row As Long
   
  Set ele = html.getElementsByClassName("nav nav-list primary left-menu")(0)
   
  Set lists = ele.getElementsByTagName("li")
  row = 1

   
  For Each li In lists
  Cells(row, 1) = li.innerText
  row = row + 1
  Next
   
  ie.Quit

End Sub
 
Upvote 0

Forum statistics

Threads
1,226,739
Messages
6,192,739
Members
453,755
Latest member
IQBS

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