我在Excel工作表中有200行,我希望将其包含在curl(或任何类型的HTTP get)中,并在第二列中查看结果。
**Column A**
123
456
789
012
...
我尝试使用Excel选项从外部网页获取数据,但它似乎不适用于同一工作表上的多行。有没有办法让我将列A中的值附加到静态URL(即:http://testurl.net/page.php?ID=[Column A]),以便页面的结果显示在B列中?我知道URL的响应将是一个只显示几个单词的休息响应。
谢谢
答案 0 :(得分:4)
您可以使用http请求对象执行此操作:
Dim oRequest As Object
Set oRequest = CreateObject("WinHttp.WinHttpRequest.5.1")
oRequest.Open "GET", "http://www.cboden.de"
oRequest.Send
MsgBox oRequest.ResponseText
如果您在代理服务器后面,可以使用以下内容:
Const HTTPREQUEST_PROXYSETTING_PROXY = 2
Dim oRequest As Object
Set oRequest = CreateObject("WinHttp.WinHttpRequest.5.1")
oRequest.setProxy HTTPREQUEST_PROXYSETTING_PROXY, "http://proxy.intern:8080"
oRequest.Open "GET", "http://www.cboden.de"
oRequest.Send
MsgBox oRequest.ResponseText
如果你想使用POST(而不是GET方法)将一些值传递给网络服务器,你可以试试这个:
Dim oRequest As Object
Set oRequest = CreateObject("WinHttp.WinHttpRequest.5.1")
oRequest.Open "POST", "http://www.cboden.de/misc/posttest.php"
oRequest.SetRequestHeader "Content-Typ", "application/x-www-form-urlencoded"
oRequest.Send "var1=123&anothervar=test"
MsgBox oRequest.ResponseText
如果你将它放入一个函数中,那么你可以在你的工作表中使用它:
Function getCustomHyperlink(ByVal pURL As String) As String
Dim oRequest As Object
Set oRequest = CreateObject("WinHttp.WinHttpRequest.5.1")
oRequest.Open "GET", pURL
oRequest.Send
getCustomHyperlink = oRequest.ResponseText
End Function
在工作表中,您可以说例如:
=getCustomHyperlink("https://www.google.com/search?q=" & A1 )
如果您的搜索值在A1
中答案 1 :(得分:0)