首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > VB >

WebBrowser打不开网页,系统浏览器可以,求解。该如何处理

2012-03-23 
WebBrowser打不开网页,系统浏览器可以,求解。WebBrowser1.Navigate http://www.eaysun.com/incs/loginveri

WebBrowser打不开网页,系统浏览器可以,求解。
WebBrowser1.Navigate "http://www.eaysun.com/incs/loginverify.asp"

用这个控件打开后面的网页,提示“无法加载”,但是系统浏览器访问正常,求解决方法。

我是想获取这个网页里面的验证码输入到Image控件,但是现在都不能打开这个页面。

下面是取得验证码的代码,下面的代码提取其他网页的验证码测试通过,例如这个:http://www.monternet.com/authcode

--------------------------------------------------------------------------

Private Sub Form_Load()
WebBrowser1.Navigate "http://www.eaysun.com/incs/loginverify.asp"
End Sub

Private Sub WebBrowser1_DocumentComplete(ByVal pDisp As Object, URL As Variant)
  Dim X, CtrlRange
  Dim ii As Long
  ii = 0
  For Each X In WebBrowser1.Document.All
  If X.tagname = "IMG" Then
  If LCase(X.src) = "http://www.eaysun.com/incs/loginverify.asp" Then
  Set CtrlRange = WebBrowser1.Document.body.createControlRange()
  CtrlRange.Add (X)
  CtrlRange.execCommand ("Copy") '获取验证码
  Image1.Picture = Clipboard.GetData '在Image1控件上显示
  Exit Sub
  End If
  ii = ii + 1
  End If
  Next

End Sub

--------------------------------------------------------------------------

现在求取这个网页的验证码方法:http://www.eaysun.com/incs/loginverify.asp

[解决办法]

VB code
Private Sub Form_Load()WebBrowser1.Navigate "about:blank"DoEventsWebBrowser1.Navigate "http://www.eaysun.com/incs/loginverify.asp"End SubPrivate Sub WebBrowser1_DocumentComplete(ByVal pDisp As Object, URL As Variant)  Dim X, CtrlRange  Dim ii As Long  ii = 0  For Each X In WebBrowser1.Document.All  If X.tagname = "IMG" Then  If LCase(X.src) = "http://www.eaysun.com/incs/loginverify.asp" Then  Set CtrlRange = WebBrowser1.Document.body.createControlRange()  CtrlRange.Add (X)  CtrlRange.execCommand ("Copy") '获取验证码  Image1.Picture = Clipboard.GetData '在Image1控件上显示  Exit Sub  End If  ii = ii + 1  End If  NextEnd Sub
[解决办法]
这个页面直接返回的是一个图片,你要以图片方式加载它.

使用WINSOCK或INET应该能直接得到它的二进制流.

而使用WEBBROWSER的话,需要用段代码:

VB code
Option ExplicitPrivate Sub Form_Load()    WebBrowser1.Navigate "about:blank"End SubPrivate Sub Command1_Click()    WebBrowser1.Document.body.innerHTML = "<IMG height=28 src=""http://www.eaysun.com/incs/loginverify.asp"" width=""100"">"End Sub
[解决办法]
这样就OK了,就是加一行DOEVENTS


VB code
Private Sub Form_Load()DoEventsWeb1.Navigate "http://www.eaysun.com/incs/loginverify.asp"End Sub
[解决办法]
VB code
Private Sub Form_Load()DoEventsWeb1.Navigate "http://www.eaysun.com/incs/loginverify.asp"End SubPrivate Sub Web1_DocumentComplete(ByVal pDisp As Object, URL As Variant)On Error Resume Next  Dim X, CtrlRange  Dim ii As Long  ii = 0  For Each X In Web1.Document.All  If X.tagname = "IMG" Then  If LCase(X.src) = "http://www.eaysun.com/incs/loginverify.asp" Then  Set CtrlRange = Web1.Document.body.createControlRange()  CtrlRange.Add (X)  CtrlRange.execCommand ("Copy") '获取验证码  Image1.Picture = Clipboard.GetData '在Image1控件上显示  Exit Sub  End If  ii = ii + 1  End If  NextEnd Sub 

热点排行