我有一个来自 HTML 源代码的大字符串(大约 1,000,000 个字符长)。我正在使用 msinet.ocx 从适当的网站查看文本。我编写了一小段代码,以便找到出现在不同关键短语(“组件附件矩阵”)之前的关键短语(“pkid =”),但它无法正常工作。这是我现在拥有的:
workbench = Cells(columnNumber, 1).Value
myURL = "http://beams.us.yazaki.com/Beams/ViewDetails.aspx?topic=document&pkid=" _
& workbench
Dim inet1 As Inet
Dim mypage As String
Set inet1 = New Inet
With inet1
.Protocol = icHTTP
.URL = myURL
mypage = .OpenURL(.URL, icString)
End With
CAMnum = InStr(mypage, "Component Accessory Matrix")
intStart = InStrRev(mypage, "pkid=", CAMnum) + 5
newnum = Mid(mypage, intStart, 6)
Cells(columnNumber, 2).Value = newnum
问题似乎出在mypage = .OpenURL(.URL, icString)
; 当我运行时len(mypage)
,它返回大约 100,000 的值,而它应该返回大约一百万的值。有人可以解释一下吗?
编辑: Gimp,我尝试了您的解决方案,但由于某种原因, ReturnStr 仍然是空的。我也尝试了 1024 而不是 2048,但这并没有改变任何东西。到目前为止,我已经复制并粘贴了我的代码。
Dim myURL
ActiveSheet.Range("a1").End(xlDown).Select lastColumn = Selection.Row
对于 columnNumber = 2 To lastColumn workbench = Cells(columnNumber, 1).Value myURL = "http://beams.us.yazaki.com/Beams/ViewDetails.aspx?topic=document&pkid=" _ & workbench Dim inet1 As Inet Dim mypage As String Dim ReturnStr As String
Set inet1 = New Inet
With inet1
.Protocol = icHTTP
.URL = myURL
mypage = .OpenURL(.URL, icString)
ReturnStr = .GetChunk(1024, icString)
End With
Do While Len(ReturnStr) <> 0
DoEvents
mypage = mypage & ReturnStr
ReturnStr = inet1.GetChunk(1024, icString)
Loop
CAMnum = InStr(mypage, "Component Accessory Matrix")
intStart = InStrRev(mypage, "pkid=", CAMnum) + 5
newnum = Mid(mypage, intStart, 6)
Cells(columnNumber, 2).Value = newnum
Next columnNumber
我在这里错过了什么吗?我在网上搜索了 GetChunk 函数,我认为我在语法上没有做错任何事情,但也许这是一些基本错误。帮助表示赞赏。