从网页获取字段值-LotusScript [英] get a field value from a webpage - lotusscript

查看:111
本文介绍了从网页获取字段值-LotusScript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要使用lotusscript从网页中读取字段值.本质上,我计划编写一个代理以转到特定的URL,从页面中获取一个值,然后将该值用于它将用户发送到的URL.

I need to read the field value from a webpage using lotusscript. Essentially I am planning on writing an agent to go to a specific URL, get a value from the page, and then use this value for the url it sends the user to.

有人可以给我指点吗?

A

推荐答案

2019年12月更新:从Notes 10(于2018年发布)开始,NotesHTTPRequest类的功能完全相同东西作为我的代码.

Update December 2019: As of Notes 10 (released in 2018) there is a NotesHTTPRequest class that does exactly the same thing as my code.

我一直都这样做,这一点也不难(在Windows上).我创建了一个类来执行此操作,因此很容易实现.

I do this all the time, it is not hard at all (on Windows). I created a class to do this, so it is very easy to implement.

这是您的称呼方式:

Dim internet As New RemoteHTML()
Dim html As String
html = internet.GetHTTP("http://www.texasswede.com/mypage.html")

就是这样,现在您只需从html字符串中提取所需的任何信息即可.

That's it, now you just pull whatever information you want out of the html string.

这是课程:

Option Public
Option Declare

Class RemoteHTML
    Private httpObject As Variant
    Public httpStatus As Integer

    Public Sub New()
        Set httpObject = CreateObject("MSXML2.ServerXMLHTTP")
    End Sub

    Public Function GetHTTP(httpURL As String) As String
        Dim retries As Integer
        retries = 0     
        Do
            If retries>1 Then
                Sleep 1     ' After the two first calls, introduce a 1 second delay betwen each additional call
            End If
            retries = retries + 1   
            Call httpObject.open("GET", httpURL, False)
            Call httpObject.send()
            httpStatus = httpObject.Status
            If retries >= 10 Then
                httpStatus = 0  ' Timeout
            End If
        Loop Until httpStatus = 200 Or httpStatus > 500 Or httpStatus = 404  Or httpStatus = 0
        If httpStatus = 200 Then
            GetHTTP = Left$(httpObject.responseText,16000)
        Else
            GetHTTP = ""
        End If
    End Function


    Public Function GetFile(httpURL As String, filename As String) As Boolean
        Dim session As New NotesSession
        Dim retries As Integer
        Dim stream As NotesStream
        Dim flag As Boolean
        Dim responsebody As variant
        Dim cnt As Long
        Dim buffer As String
        Dim tmp As Byte

        Set stream = session.CreateStream
        retries = 0     
        Do
            If retries>1 Then
                Sleep 1     ' After the two first calls, introduce a 1 second delay betwen each additional call
            End If
            retries = retries + 1   
            Call httpObject.open("GET", httpURL, False)
            Call httpObject.send()
            httpStatus = httpObject.Status
            If retries >= 10 Then
                httpStatus = 0  ' Timeout
            End If
        Loop Until httpStatus = 200 Or httpStatus > 500 Or httpStatus = 404  Or httpStatus = 0
        If httpStatus = 200 Then
            flag = stream.Open(filename, "binary")
            If flag = False Then
                MsgBox "Failed to create " & filename & "..."
                GetFile = False 
                Exit function
            End If
            responsebody = httpObject.ResponseBody
            ForAll r in responsebody
                tmp = r
                Call Stream.Write(Chr$(CInt(tmp)))
                cnt = cnt + 1
            End ForAll
            MsgBox cnt
            GetFile = True
        Else
            GetFile = False
        End If

    End Function

    Private Function getString(ByVal StringBin As string)
        Dim intCount As Long
        getString =""
        For intCount = 1 To LenB(StringBin)
            getString = getString & Chr( Asc(MidB(StringBin, intCount, 1)) )
        Next
    End Function

End Class

这篇关于从网页获取字段值-LotusScript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆