vb.net - how to get captcha image if src use java function? -
how can scrape captcha this website captchaimage.
i tried mshtml website uses java script function display retrieve captcha in it's src. please try , answer me how can achieve this.
imports mahapps.metro.controls imports system.net imports system.windows.forms class mainwindow inherits metrowindow private sub metrowindow_loaded(sender object, e routedeventargs) wb.navigate("https://www.irctc.co.in/eticketing/loginhome.jsf") addhandler wb.loadcompleted, addressof wb_loaded end sub private sub btngo_click(sender object, e routedeventargs) handles btngo.click dim htmldoc mshtml.ihtmldocument2 = wb.document dim usrtxtdoc mshtml.ihtmlelement = htmldoc.all.item("j_username", 0) dim usrpwddoc mshtml.ihtmlelement = htmldoc.all.item("j_password", 0) dim captchadoc mshtml.ihtmlelement = htmldoc.all.item("j_captcha", 0) usrtxtdoc.innertext = txtusrname.text usrpwddoc.innertext = txtpwd.text captchadoc.innertext = txtcaptcha.text end sub private sub wb_loaded(sender object, e system.windows.navigation.navigationeventargs) msgbox("loaded") dim htmldoc mshtml.ihtmldocument2 = wb.document dim htmldoc2 mshtml.htmldocument = wb.document dim captchaimg mshtml.htmlimg = htmldoc.all.item("cimage", 0) dim bitmap new bitmapimage bitmap.begininit() bitmap.urisource = new uri(wb.findresource("captchaimage")) bitmap.endinit() imgcaptcha.source = bitmap end sub private sub wb_navigated(sender object, e navigationeventargs) handles wb.navigated lblwbstatus.content = "load completed" end sub private sub wb_navigating(sender object, e navigatingcanceleventargs) handles wb.navigating lblwbstatus.content = "navigating please wait" end sub private sub lblwbstatus_mousedoubleclick(sender object, e mousebuttoneventargs) handles lblwbstatus.mousedoubleclick wb.refresh() end sub end class you can download source this link
normally this:
dim htmldoc mshtml.ihtmldocument2 = wb.document.domdocument dim captchaimg mshtml.htmlimg = htmldoc.all.item("cimage", 0) dim imgrange ihtmlcontrolrange = htmldoc.body.createcontrolrange() each img ihtmlimgelement in htmldoc.images if img.nameprop = "captchaimage" imgrange.add(img) imgrange.execcommand("copy", false, nothing) using bmp bitmap = clipboard.getdataobject().getdata(dataformats.bitmap) bmp.save("c:\test.bmp") end using end if next however image has alpha channel doesn't copied clipboard because of internet explorer issues (as can read here copying image page results in black image).
other ways check on internet explorer cache, image won't cached because of http headers, out of luck.
Comments
Post a Comment