VBA, MS Access MS Access в примерах

Тело HTML страницы по URL

Public Function GetHTMLPageByURL(URL$) As String
'--------------------------------------------------------------------
' Функция возвращает тело переданной в URL страницы
'--------------------------------------------------------------------

Dim oXMLHTTP As Object
    Set oXMLHTTP = CreateObject("MSXML2.XMLHTTP")
    With oXMLHTTP
        .Open "GET", URL, False
        .send
        If .Status = 200 Then
            GetHTMLPageByURL = .responseText ' Тело HTML стр.
            'Debug.Print GetHTMLPageByURL
        End If
    End With
    Set oXMLHTTP = Nothing

End Function


Второй вариант через IE

Public Function GetHTMLPageByURL2(URL$) As String
Const READYSTATE_COMPLETE = 4
Dim IE As Object
Dim html As Object
Dim htmlBody As Variant


    Set IE = CreateObject("InternetExplorer.Application")
    'IE.Top = 0
    'IE.Left = 0
    'IE.Width = 800
    'IE.Height = 600
    
    'IE.Visible = True
    IE.Visible = False
    IE.navigate URL$


'Wait until IE is done loading page
    Do While IE.ReadyState <> READYSTATE_COMPLETE
        DoEvents
    Loop

'HTML document returned
    Set html = IE.Document
    GetHTMLPageByURL2 = html.DocumentElement.innerHTML

    'IE.Visible = True
    IE.Quit
    Set IE = Nothing

End Function

Назад ToTop
L.E. 04.12.2018
Рейтинг@Mail.ru