excel vba - VBA: How to get a hidden href within <td> tag -


i'm trying scores soccer world cups since 1930, in link match ups listed , clicking in team new window pop summary i'm looking for. problem in html source code don't see <a> tag href inside of is, i'm trying simulate click event following vba code:

link: http://www.flashscore.com/soccer/world/world-cup-1990/results/

vba code:

sub test()   dim url string   dim ie internetexplorer   dim htmldoc htmldocument   dim tdelements ihtmlelementcollection   dim tdelement htmltablecell   dim integer  url = "http://www.flashscore.com/soccer/world/world-cup-1990/results/"  set ie = new internetexplorer  ie     .navigate url     .visible = true      while .busy or .readystate <> readystate_complete: doevents: wend          set htmldoc = .document     end          set tdelements = htmldoc.getelementsbytagname("td")          each tdelement in tdelements              if tdelement.title = "click match detail!"                 tdelement.click             end if         next     ie.quit end sub 

i'd 1 differently, you're trying achieve requires massive overhead , might take on wild goose chase of links, actions, loops, , whatnot. instead of emulating actions, it's better emulating results of actions.

take example germany - argentina match. when click on it, opens pop-up:

enter image description here

of particular note here url of pop-up. intuitively enough, url has weird combination might possibly unique identifier. first thing check tag row in table clicked.

enter image description here

check highlighted part: resembles address in our pop-up closely, albeit there 4 (4) characters @ beginning. collapsing row , cross-checking against other rows, come conclusion rows use similar format:

enter image description here

removing g_1_ id attribute of tr tag gives unique identifier every match. i'll taking sanitized id italy - england match , input generic url. we'll in tab pop-up's address bar locked:

enter image description here

voila. page open in tab, , there can want match summary. can check head-to-head changing #match-summary #h2h;overall.

enter image description here

why matter?

because it's safer. since you're using excel, have sheets @ control. safest way record these id attributes each row into, say, column. loop on column, concatenating produce target urls.

then loop on urls , want exact pages you're looking for. there's no need anymore original link/table @ point since details in "summary" pages anyway.

hope helps , luck.

follow-up edit

as feel bit guilty not posting code, here's attempt @ producing id values world cup section. note took liberties code, modify suit approach better. providing way id values. else you.

sub test()      dim url string     dim ie new internetexplorer     dim htmldoc htmldocument     dim dictobj object: set dictobj = createobject("scripting.dictionary")     dim trowid string      url = "http://www.flashscore.com/soccer/world/world-cup-1990/results/"      ie         .navigate url         .visible = true         until .readystate = readystate_complete: doevents: loop         set htmldoc = .document     end      htmldoc         'target set of tables.         set tblset = .getelementbyid("fs-results")         'index starts @ 0. world cup playoffs (0), world cup (1),         'qualifiers (2), etc... targeting tbody right away, there         'only 1 (1) tbody tag per row anyway.         set mtbl = tblset.getelementsbytagname("tbody")(1)         set trows = mtbl.getelementsbytagname("tr")         dictobj             'if if value not yet in dictionary, store it.             each trow in trows                 'remove first 4 (4) characters.                 trowid = mid(trow.getattribute("id"), 5)                 if not .exists(trowid)                     .add trowid, empty                 end if             next trow         end     end      'print out each of id values.     each key in dictobj         debug.print key     next key      set ie = nothing  end sub 

which returns following id values world cup table (not playoffs!):

04lfr6g7 6rnojjg8 nww8zbgl t0xczu8r dky0pgu3 jsy4odf9 k4ycddti 2qm7ld3j bxvdgk2k tdu0f9he 65hr8yfm lusw7has jbqaxxo8 yzy3yivf n1hjsn11 hvintsoe rhudqzpd xfs51jmd ncyhhvnq 4b34kglp o0kz7ljh lpqe9eug uhlqlbvs fnqaafq9 ckpewd92 emjru8wl knt4etw1 nrnnvlhr b3t12wxk jwuc3ciq n9rdmipl pajw714b gzns8sk5 gwr6bzb3 uxw8nx9f bex1cgec 

hope helps more. kindly make sure read comments. luck!


Comments

Popular posts from this blog

php - SPIP: From Tag directly to an article -

jquery - isAjaxRequest always return false -

ruby on rails - In a controller spec, how to find a specific tag in the generated view? -