vba 卷曲 URL 并在 Excel 单元格中发布结果?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26681866/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Curl URL and post results in Excel cell?
提问by AAA
I have 200 rows in an Excel sheet that I would like to include in a curl (or any kind of HTTP get) and see the results in a second column.
我在 Excel 工作表中有 200 行,我想将其包含在 curl(或任何类型的 HTTP get)中,并在第二列中查看结果。
**Column A**
123
456
789
012
...
I have tried using the Excel option to get data from an external web page but it doesn't appear to work for multiple row on the same sheet. Is there a way for me to append the value in Column A to a static URL (ie:http://testurl.net/page.php?ID=[ColumnA]) so that the result of the page is shown in Column B? I know the response from the URL will be a rest response that will display only a couple words.
我曾尝试使用 Excel 选项从外部网页获取数据,但它似乎不适用于同一工作表上的多行。有没有办法让我将 A 列中的值附加到静态 URL(即:http: //testurl.net/page.php?ID=[Column A]),以便页面结果显示在 Column 中乙?我知道来自 URL 的响应将是一个仅显示几个词的休息响应。
Thank you
谢谢
回答by cboden
you can do this by using a http request object:
您可以通过使用 http 请求对象来做到这一点:
Dim oRequest As Object
Set oRequest = CreateObject("WinHttp.WinHttpRequest.5.1")
oRequest.Open "GET", "http://www.cboden.de"
oRequest.Send
MsgBox oRequest.ResponseText
If you are behind a proxy you can use something like this:
如果你在代理后面,你可以使用这样的东西:
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
and if you want to use POST (instead of the GET method) to pass some values to the webserver, you can try this:
如果你想使用 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
if you put it into a function then you can use it in you worksheet:
如果将其放入函数中,则可以在工作表中使用它:
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
within the worksheet you can then say for example:
在工作表中,您可以说例如:
=getCustomHyperlink("https://www.google.com/search?q=" & A1 )
if your search value is in A1
如果您的搜索值在 A1 中