vba - Web scraping - create object for IE -


sub get_data()   set ie = createobject("internetexplorer.application") ie.visible = true ie.navigate "http://www.scramble.nl/military-database/usaf" while ie.busy     application.wait dateadd("s", 1, now) loop sendkeys "03-3114" sendkeys "{enter}"   end sub 

the code below searches keyboard typed value 03-3114 , gets data in table. if 'd search value in cell a1 , scrape values table "code, type, cn, unit" in cell range ("b1:e1") should do?

you using sendkeys highly unreliable :) why not find name of textbox , search button , directly interact shown below?

sub get_data()     dim ie object, objinputs object      set ie = createobject("internetexplorer.application")     ie.visible = true     ie.navigate "http://www.scramble.nl/military-database/usaf"      while ie.readystate <> 4: doevents: loop      '~~> id of textbox want output     ie.document.getelementbyid("serial").value = "03-3114"      '~~> here try identify search button , click     set objinputs = ie.document.getelementsbytagname("input")     each ele in objinputs         if ele.name "sbm"             ele.click             exit         end if     next end sub 

note: understand how got names serial , sbm, refer explanation given above image below.

the code below searches keyboard typed value 03-3114 , gets data in table. if 'd search value in cell a1 , scrape values table "code, type, cn, unit" in cell range ("b1:e1") should do?

directly put value a1 in lieu of hardcoded value

ie.document.getelementbyid("serial").value = sheets("sheet1").range("a1").value 

to values table, identify elements of table right clicking on in browser , clicking on "inspect/inspect element(in chrome inspect)" shown below.

enter image description here

i can give code want yourself. if still stuck update question code tried , take there.

interesting read: html parsing of cricinfo scorecards


Comments

Popular posts from this blog

mysql - Dreamhost PyCharm Django Python 3 Launching a Site -

java - Sending SMS with SMSLib and Web Services -

java - How to resolve The method toString() in the type Object is not applicable for the arguments (InputStream) -