html - 与 InternetExplorerMedium 一起使用的 MSXML2.ServerXMLHTTP.6.0 的 VBA 问题
问题描述
我喜欢尽可能使用 MSXML2.ServerXMLHTTP.6.0,因为它更快。但是,当我需要与网站交互时,我无法弄清楚如何使用它。那可能是另一个问题。
但是,当我使用以下代码时,我得到了所需的结果......
Sub GoogleSfund()
Set objIExplorer = New InternetExplorerMedium
objIExplorer.Silent = True
objIExplorer.Visible = False 'for testing change to true
objIExplorer.Navigate "https://www.google.com/search?q=DWCPF"
Do While objIExplorer.Busy Or Not objIExplorer.ReadyState = 4: DoEvents: Loop
a = objIExplorer.Document.body.getElementsByTagName("g-card-section")
pos1 = InStr(a.innerText, "INDEXDJX: DWCPF")
pos2 = InStr(a.innerText, "Disclaimer")
b = Mid(a.innerText, pos1, pos2 - pos1)
b = Replace(b, vbCrLf & vbCrLf, vbCrLf)
MsgBox b
TSP_Test.lblSfund.Caption = b
objIExplorer = ""
End Sub...
使用 (MSXML2.ServerXMLHTTP.6.0) 它不会抓取具有相同 URL 的页面
Sub GoogleSfundFAST()
Dim sSourceUrl As String
Dim HttpReq As Object
Set HttpReq = CreateObject("MSXML2.ServerXMLHTTP.6.0")
Dim HTMLDoc As New MSHTML.HTMLDocument
Dim HTMLH3Doc As New MSHTML.HTMLDocument
Dim HTMLInstProcDoc As New MSHTML.HTMLDocument
sSourceUrl = "https://www.google.com/search?q=dwcpf"
'sSourceUrl = "https://www.google.com/search"
HttpReq.Open "GET", sSourceUrl, False
HttpReq.send
If HttpReq.Status = 200 Then
HttpReq.getAllResponseHeaders
HTMLDoc.body.innerHTML = HttpReq.responseText
End If
Dim Obj As MSHTML.HTMLGenericElement
Dim Heading As MSHTML.IHTMLElementCollection
Dim HD As HTMLElementCollection
Debug.Print HTMLDoc.body.innerHTML
End Sub
有任何想法吗?
解决方案
推荐阅读
- c++ - 用不同的模板参数初始化模板类
- linux - 如何修改 Docker 权限异常
- reactjs - React Native TextInput 仅显示状态值
- javascript - 响应 415(不支持的媒体类型)
- flutter - 在 Flutter 中使用 OrientationBuilder 打开键盘时如何避免方向更改?
- python - Python Pandas:group by 正在删除列
- javascript - 使用 jQuery 加载页面时如何仅显示一种语言
- pyqt5 - 突出显示qpushbutton pyqt中的单个字符
- android - 在 Android/iOS 应用中访问 Google Ads 信息
- javascript - 如何在不重置到原始位置的情况下将元素从一个 div 移动到另一个 div?(interact.js)