登录网页并在vb6中捕获屏幕截图

时间:2013-11-13 08:54:33

标签: http vb6 screenshot

我有一个visual basic 6应用程序需要从特定网站获取图片,但问题是用户必须在浏览器上打开网页并登录网页然后下载图片并将其上传到vb6应用程序。是否有可能让vb6进入该网页并登录并捕获屏幕截图并将其保存在特定文件夹中而无需打开浏览器? 该URL默认打开登录页面,您必须先登录才能访问图片页面,我们只需要拍摄一个屏幕截图并裁剪它。

这在纯VB6中是否可行?

1 个答案:

答案 0 :(得分:1)

以下是一些非常通用的代码,可以将您登录到网站。基本上是在浏览器文档中找到控件并填写正确的值。由于您没有提供任何代码来构建它,因此您可以填写所有正确的值。这是使用 Microsoft Internet Controls 将浏览器控件添加到表单。

Private Sub Form_Load()
    Dim i As Integer

    WebBrowser1.Navigate ("http://URL of the page you want to go to")
    Do While WebBrowser1.ReadyState <> READYSTATE_COMPLETE
        DoEvents
    Loop
    If InStr(WebBrowser1.LocationURL, "http://targetwebsite/login.aspx") Then
        On Error Resume Next
        For i = 0 To WebBrowser1.Document.Forms(0).length - 1
            ' Uncommenting the MsgBox method will display the control names and help find the controls you are looking for
            'MsgBox WebBrowser1.Document.Forms(0)(i).Type & ", " & WebBrowser1.Document.Forms(0)(i).Name
            If WebBrowser1.Document.Forms(0)(i).Type = "text" Then
                WebBrowser1.Document.Forms(0)(i).Value = "user name"
            End If
            If WebBrowser1.Document.Forms(0)(i).Type = "password" Then
                WebBrowser1.Document.Forms(0)(i).Value = "user password"
            End If
        Next i
        ' now find and click the submit button
        For i = 0 To WebBrowser1.Document.Forms(0).length - 1
            If WebBrowser1.Document.Forms(0)(i).Type = "submit" Then
                WebBrowser1.Document.Forms(0)(i).Click
            End If
        Next i
    End If

    ' You should now be logged in and loading the page you want
End Sub
相关问题