我使用 vba 创建了两个脚本来从 webpage 获取表格内容。要访问表格内容,我必须首先在 410611
下的 UID#
旁边填写 Search by UID
。然后,我点击了 go
按钮,我看到了表格内容。
我使用 selenium 取得了成功:
Sub FetchContent()
Dim oInput As Object, oElem As Object
With CreateObject("Selenium.ChromeDriver")
.get "https://www.theclearinghouse.org/uid-lookup"
.SwitchToFrame .FindElementById("uidlookup", timeout:=10000)
Set oInput = .FindElementByCss("input[name='UidNum']", timeout:=5000)
oInput.SendKeys "410611"
.FindElementByCss("input#SubmitUid", timeout:=5000).Click
Set oElem = .FindElementByCss("table#uid", timeout:=5000)
MsgBox oElem.Text
End With
End Sub
但是,我希望使用 xmlhttp 请求获得相同的内容。我试过如下,但不幸的是它不起作用。该脚本既不会引发任何错误,也不会在即时窗口中打印任何内容。不过,我在 python 中使用相同的逻辑取得了成功。
使用 xmlhttp 请求(不起作用):
Sub FetchContent()
Const URL = "https://uid.theclearinghouse.org/list.php"
With CreateObject("MSXML2.XMLHTTP")
.Open "POST", URL, False
.setRequestHeader "content-type", "application/x-www-form-urlencoded"
.setRequestHeader "referer", "https://uid.theclearinghouse.org/index.php"
.send ("UidNum=410611&SubmitUid=Go%21")
Debug.Print .responseText
End With
End Sub
<块引用>
如何使用 xmlhttp 请求访问表格内容?