VBScript: Cannot find/click a button on webpage automatically -
could use here please. have maintain bunch of laptops never connect internet (security reasons). there single laptop of same type , disk image connect internet patch management.
they run windows 10 , on internet laptop use script uses wsus2 cab file find missing updates.
now want take script's output command line , have download missing updates me.
in script, import findings, find kb number, append kb number end of "https://www.catalog.update.microsoft.com/search.aspx?q=", webpage in variable, parse variable patch name, , try download button corresponds patch name.
for example, output says "2017-07 security update adobe flash player windows 10 version 1703 x64-based systems (kb4025376)" missing.
so url, , download source... looks this:
<td class="resultsbottomborder resultspadding" id="9ebe5d13-4966-4cdb-a612-9780df621411_c1_r0"> <a id='9ebe5d13-4966-4cdb-a612-9780df621411_link' href="javascript:void(0);" onclick='gotodetails("9ebe5d13-4966-4cdb-a612-9780df621411");'> 2017-07 security update adobe flash player windows 10 version 1703 x64-based systems (kb4025376) </a> </td> <td class="resultsbottomborder resultspadding" id="9ebe5d13-4966-4cdb-a612-9780df621411_c2_r0"> windows 10 </td> <td class="resultsbottomborder resultspadding" id="9ebe5d13-4966-4cdb-a612-9780df621411_c3_r0"> security updates </td> <td class="resultsbottomborder resultspadding " id="9ebe5d13-4966-4cdb-a612-9780df621411_c4_r0"> 7/11/2017 </td> <td class="resultsbottomborder resultspadding" id="9ebe5d13-4966-4cdb-a612-9780df621411_c5_r0"> n/a </td> <td class="resultsbottomborder resultspadding resultssizewidth" id="9ebe5d13-4966-4cdb-a612-9780df621411_c6_r0"> <span id="9ebe5d13-4966-4cdb-a612-9780df621411_size">20.7 mb</span> <span class="nodisplay" id="9ebe5d13-4966-4cdb-a612-9780df621411_originalsize">21711921</span> </td> <td class="resultsbottomborder resultsbuttonwidth" id="9ebe5d13-4966-4cdb-a612-9780df621411_c7_r0"> <input id="9ebe5d13-4966-4cdb-a612-9780df621411" class="flatlightbluebutton" type="button" value='download' /> </td>
i "try" because script doesn't work.
before posting, looked @ click button on webpage via vbscript?. no help. i'm posting don't think didn't rtfm beforehand.
the script fails on (yeah, i'm hardcoding id working... variable later):
ie.document.getelementsbyid("9ebe5d13-4966-4cdb-a612-9780df621411").item(0).click
i tried using http provider, rather ie object, , failed too:
http.document.getelementbyid("9ebe5d13-4966-4cdb-a612-9780df621411").item(0).click
here's script:
' test data -- not going in production script. output wsus scan ' imported here. dim findings(1) findings(0) = "2017-07 cumulative update windows 10 version 1703 x64-based systems (kb4025342_fail)" findings(1) = "2017-07 security update adobe flash player windows 10 version 1703 x64-based systems (kb4025376)" ' ***** ' production script follows ' ***** ' array hold findings wsus output. ' array change in size , not declared fixed. dim patches() ' counter. dim : = 0 ' ints parsing strings created fromn findings. dim firstparen, lastparen, length dim kb dim kbandnamehash : set kbandnamehash = createobject("scripting.dictionary") ' iterate through results , populate array... putting stuff ' array because original ms script redirected findings ' output -- couldn't automatically afterwards. each item in findings redim preserve patches(i) patches(i) = item = + 1 next each thingy in patches ' need parse string find kb number. "(kb...)" appears ' unique. firstparen = instr(thingy, "(kb") lastparen = instr(thingy, ")") ' -1 in line exclude closing paren in (kb...) -- want digits ' no special characters. length = ((lastparen - 1) - firstparen) ' debug ' wscript.echo "firstparen: " & firstparen & vbcr & _ ' "lastparen: " & lastparen & vbcr & _ ' "length: " & length & vbcr ' kb number reading string next spot after first paren ' length of number (because it's not fixed length). kb = mid(thingy, firstparen + 1, length) ' create hash kb , name. hash easier work ' 2 dimensional array. kb needed patch url. name ' needed download once page loaded. kbandnamehash.add kb, thingy next ' provides access scripting dictionary dim k : k = kbandnamehash.keys dim n : n = kbandnamehash.items ' patches dim http : set http = createobject("winhttp.winhttprequest.5.1") dim partialurl : partialurl = "https://www.catalog.update.microsoft.com/search.aspx?q=" dim webpage, j ' ##### ' tried from: https://stackoverflow.com/questions/5292860/click-button-on-webpage-via-vbscript dim objwshshell,ie,searchstr set objwshshell = wscript.createobject("wscript.shell") set ie = createobject("internetexplorer.application") ' ##### each key in k http .open "get", partialurl & key, true .send .waitforresponse end ' load webpage source memory. webpage = http.responsetext ' find postion of name of finding. j = instr(webpage, kbandnamehash.item(key)) if http.status = 200 if j > 0 ' script no longer works. ' tried this: ' http.document.getelementbyid("9ebe5d13-4966-4cdb-a612-9780df621411").item(0).click ' ##### ' tried from: https://stackoverflow.com/questions/5292860/click-button-on-webpage-via-vbscript ie .visible = true .navigate partialurl & key while .busy wscript.sleep 100 loop .document.getelementsbyid("9ebe5d13-4966-4cdb-a612-9780df621411").item(0).click end ' ##### else msgbox "did not find download link for: " & vbcr & vbcr &_ kbandnamehash.item(key) & vbcr & vbcr &_ "please manually check " & key, 48, "patch not found" end if else ' todo: handle <>200 status end if next set http = nothing set kbandnamehash = nothing wscript.quit
any assistance on how can download button corresponds name of patch specified appreciated!!!
thanks!
Comments
Post a Comment