首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >XMLHTTP60请求不显示整个HTML文档

XMLHTTP60请求不显示整个HTML文档
EN

Stack Overflow用户
提问于 2018-08-04 03:59:47
回答 1查看 375关注 0票数 2

我正在尝试从一个网站获取HTML文档,还有什么,抓取数据!

不幸的是,我无法获得与该网页相关联的整个HTML文档。我的debug.print语句没有像我希望的那样显示整个网页,它被截断了。我是编程新手,如果能帮上忙,我将不胜感激!

我的代码如下:

代码语言:javascript
复制
Const SecForm4 As String = "https://www.secform4.com/significant-buys.htm"

Sub LoadWebPage()

    Dim XMLReq As New MSXML2.XMLHTTP60

    XMLReq.Open "GET", SecForm4, False
    XMLReq.send

    If XMLReq.Status <> 200 Or XMLReq.readyState <> 4 Then
        MsgBox "Problem" & vbNewLine & XMLReq.Status & "-" & XMLReq.statusText
        Exit Sub
    End If

    ParsingHTMLDocument XMLReq.responseText

End Sub

Sub ParsingHTMLDocument(HTMLText As String)

    Dim HTMLDoc As New MSHTML.HTMLDocument

    HTMLDoc.body.innerHTML = HTMLText
    Debug.Print HTMLText

End Sub
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-08-04 04:05:39

下面是抓取文档和表格方面的工作。您不太可能能够将整个文档打印到“即时”窗口,因为它对capacity有限制。相反,您可以写入文本文件并进行检查。

将文件路径"C:\Users\User\Desktop\Test.txt"更改为1。

代码语言:javascript
复制
Option Explicit
Public Sub GetInfo()
    Dim sResponse As String, i As Long, html As New HTMLDocument, hTable As HTMLTable
    With CreateObject("MSXML2.XMLHTTP")
        .Open "GET", "https://www.secform4.com/significant-buys.htm", False
        .Send
        sResponse = StrConv(.responseBody, vbUnicode)
    End With
    sResponse = Mid$(sResponse, InStr(1, sResponse, "<!DOCTYPE "))
    WriteTxtFile sResponse
    With html
        .body.innerHTML = sResponse
        Set hTable = .getElementById("filing_table")
        MsgBox hTable.localName
    End With
End Sub

 Public Sub WriteTxtFile(ByVal aString As String, Optional ByVal filePath As String = "C:\Users\User\Desktop\Test.txt")
    Dim fso As Object, Fileout As Object
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set Fileout = fso.CreateTextFile(filePath, True, True)
    Fileout.Write aString
    Fileout.Close
End Sub

需要对HTML对象库的引用。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51679384

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档