getelementsbyclassname Excel vba - error on repeated calls -


morning,

i having trouble webscrape excel, whereby getelementsbyclassname failing act on objects, throwing "object doesn't support property or method" error.

the problem appears when object feeding getelementsbyclassname result of getelementsbyclassname method. not sure why, particularly can class name when acting on larger object...

here code extract

''''boring variables declaration i've cut out''''  'initialise ie dim ieapp new internetexplorer  set ieapp = new internetexplorer  ieapp.visible = true 'jb  'open page , wait page load   ieapp.navigate ("http://www.anicewebsite.com")   until ieapp.readystate = readystate_complete , ieapp.busy = false     doevents   loop  set htmldoc = ieapp.document set reflocation = sheets("info_dump").range("locationrefcell") set trelements = htmldoc.getelementsbyclassname("basic-details") each trelement in trelements         'select lhs box , extract info         set tdelement = trelement.getelementsbyclassname("tieredtoggle")         'write start/end locations         '''''this next line throws error'''''          data_str = tdelement.getelementsbyclassname("title").innertext         '''''as does'''''         myobject=tdelement.getelementsbyclassname("title")          reflocation.offset(1, 2).value = data_str  next 'close tr loop          

however, can 'title' object via

for each trelement in trelements         set myobject=trelement.getelementsbyclassname("title") next 'close tr loop 

so error is, presumably, tdelement (a disphtmlelement collection), tried attach image of lack reputation (see link @ end of post)...

many help.

ps. webpage structured, roughly, 2-column table rows isolate "basic-details". first column "tiered toggle" , items want inner text in eg. "title". need use tieredtoggle objects in each column have repeated class names

http://i.stack.imgur.com/1tyb6.png

you can use innertext.

data_str = tdelement.getelementsbyclassname("title")(0).innertext 

instead of ("title")(0) can enter index value element present.


Comments

Popular posts from this blog

qt - Using float or double for own QML classes -

Create Outlook appointment via C# .Net -

ios - Swift Array Resetting Itself -