如何从this website抓取验证码 captchaImage。
我尝试了MSHTML,但是这个网站使用java脚本函数在它的src中显示检索验证码。请尝试回答我如何实现这一目标。
Imports MahApps.Metro.Controls
Imports System.Net
Imports System.Windows.Forms
Class MainWindow
Inherits MetroWindow
Private Sub MetroWindow_Loaded(sender As Object, e As RoutedEventArgs)
wb.Navigate("https://www.irctc.co.in/eticketing/loginHome.jsf")
AddHandler wb.LoadCompleted, AddressOf wb_Loaded
End Sub
Private Sub btngo_Click(sender As Object, e As RoutedEventArgs) Handles btngo.Click
Dim htmldoc As MSHTML.IHTMLDocument2 = wb.Document
Dim usrtxtdoc As MSHTML.IHTMLElement = htmldoc.all.item("j_username", 0)
Dim usrpwddoc As MSHTML.IHTMLElement = htmldoc.all.item("j_password", 0)
Dim captchadoc As 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 As Object, e As System.Windows.Navigation.NavigationEventArgs)
MsgBox("Loaded")
Dim htmldoc As MSHTML.IHTMLDocument2 = wb.Document
Dim htmldoc2 As MSHTML.HTMLDocument = wb.Document
Dim captchaimg As MSHTML.HTMLImg = htmldoc.all.item("cimage", 0)
Dim bitmap As New BitmapImage
bitmap.BeginInit()
bitmap.UriSource = New Uri(wb.FindResource("captchaImage"))
bitmap.EndInit()
imgcaptcha.Source = bitmap
End Sub
Private Sub wb_Navigated(sender As Object, e As NavigationEventArgs) Handles wb.Navigated
lblwbstatus.Content = "Load Completed"
End Sub
Private Sub wb_Navigating(sender As Object, e As NavigatingCancelEventArgs) Handles wb.Navigating
lblwbstatus.Content = "Navigating Please wait"
End Sub
Private Sub lblwbstatus_MouseDoubleClick(sender As Object, e As MouseButtonEventArgs) Handles lblwbstatus.MouseDoubleClick
wb.Refresh()
End Sub
End Class
您可以从this link
下载来源答案 0 :(得分:0)
通常你会这样做:
sorted(temp_dict.items(), key=lambda x: int(x[1]))
然而,由于互联网资源管理器问题,图片有一个不会被复制到剪贴板的Alpha通道(正如您在此处阅读Copying image from page results in black image)。
其他方法是检查Internet Explorer缓存,但由于HTTP标头,该图像不会被缓存,因此您运气不佳。
答案 1 :(得分:0)
上面的代码在考虑以下方面非常有效: 1-项目类型-如您的网页目标示例(“ IMG”)中所述。 2-图像专有名称示例:CaptchaImg.jpg被写为CaptchaImg.jpg 3-添加对(mshtml)的引用并将mshtml导入您的项目 4-右键单击您项目上的引用->单击添加引用-> ->浏览按钮单击-选择或导航到---> C:\ Windows \ assembly \ GAC \ Microsoft.mshtml \ 7.0.3300.0__b03f5f7f11d50a3a \ Microsoft.mshtml.dll ---->单击确定按钮---这会将Microsoft.mshtml.dll添加到您的引用中 将finallt导入为项目(导入mshtml)。 5-将目录bmp.Save(“ c:\ test.bmp”)--->更改为例如bmp.Save(“ c:\ test \ test.bmp”) 享有安全和管理权。