Lotus notes 从网页获取字段值-lotusscript

Lotus notes 从网页获取字段值-lotusscript,lotus-notes,Lotus Notes,我需要使用lotusscript从网页读取字段值。本质上,我正计划编写一个代理,以转到特定的URL,从页面中获取一个值,然后将该值用于它发送给用户的URL 谁能给我一个指针吗 A如果您的代码将在Windows上运行,则可以使用WinHTTP或XMLHTTP COM类来读取网页。如果代码将在任何其他平台上运行,您最好使用Java而不是LotusScript。2019年12月更新:自Notes 10(2018年发布)起,有一个NotesHTTPRequest类的功能与我的代码完全相同 我一直这样做,

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

谁能给我一个指针吗


A

如果您的代码将在Windows上运行,则可以使用WinHTTP或XMLHTTP COM类来读取网页。如果代码将在任何其他平台上运行,您最好使用Java而不是LotusScript。

2019年12月更新:自Notes 10(2018年发布)起,有一个NotesHTTPRequest类的功能与我的代码完全相同

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

以下是您如何称呼它:

Dim internet As New RemoteHTML()
Dim html As String
html = internet.GetHTTP("http://www.texasswede.com/mypage.html")
就是这样,现在您只需从html字符串中提取您想要的任何信息

下面是课堂:

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

若你们试图从一个NotesField中阅读,你们可以选择下面的方法。创建该类是为了专门处理RichText项到html字符串的导出,以便查找NotesRichText项中可能存在的隐藏嵌入图像(粘贴的图形)。 函数ExportDoc()将html响应文本复制到当前文档的用户定义字段中:

Public Class RTExporter
    session As NotesSession
    db As NotesDatabase
    doc As NotesDocument
    obj As Variant
    url As String

    Public Sub New()
        Set Me.session = New NotesSession()
        Set db = session.CurrentDatabase
        Set obj = CreateObject("Microsoft.XMLHTTP")
    End Sub

    ' Handles export from eventual NotesRichTextitems in the form of HTml
    Public Function ExportDoc(hostUrl As String, doc As NotesDocument, rtFieldName As String, htmlFieldName As String)
        Dim htmlString As String    

        url = hostUrl & Me.db.FilePath & "/0/" & doc.Universalid & "/" & rtFieldname & "?openfield&charset=utf-8        

        Set Me.doc = doc    

        htmlString = GetHtmlFromField(htmlFieldName)

        Call doc.ReplaceItemValue(htmlFieldName, htmlString)

        Call doc.Save(True, False)
    End Function

    ' Get http response text and store it in <fieldname>
    Private Function GetHtmlFromField(rtFieldName As String) As String
        Dim html As String      

        On Error Goto ERH

        obj.open "GET", Me.url, False, "", ""

        obj.send("")

        GetHtmlFromField = Trim$(obj.responseText)

        Exit Function
ERH:
        GetHtmlFromField = "Error " & Err & ": " & Error & " occured on line: " & Erl
    End Function

End Class
公共类RTExporter
会话作为备注会话
db As NotesDatabase
注释文件
obj作为变体
url作为字符串
公共分新()
Set Me.session=New NotesSession()
Set db=session.CurrentDatabase
设置obj=CreateObject(“Microsoft.XMLHTTP”)
端接头
'处理以HTml形式从最终NotesRichTextitems导出
公共函数ExportDoc(hostUrl作为字符串,doc作为NotesDocument,rtFieldName作为字符串,htmlFieldName作为字符串)
作为字符串的Dim htmlString
url=hostUrl&Me.db.FilePath&“/0/”&doc.Universalid&“/”&rtFieldname&“?openfield&charset=utf-8
Set Me.doc=doc
htmlString=GetHtmlFromField(htmlFieldName)
调用doc.ReplaceItemValue(htmlFieldName,htmlString)
调用doc.Save(真、假)
端函数
'获取http响应文本并将其存储在
私有函数GetHtmlFromField(rtFieldName作为字符串)作为字符串
将html设置为字符串
关于错误Goto-ERH
obj.open“GET”、Me.url、False、“”
对象发送(“”)
GetHtmlFromField=Trim$(对象响应文本)
退出功能
呃:
GetHtmlFromField=“Error”&Err&“:”&Error&“发生在以下行:”&Erl
端函数
末级

也许这可以帮助你:谢谢Karl。这很好-感谢提供的细节。非常好的Karl-即使在三年之后!