我正在编写一个Excel宏,以从我们公司使用的网页中抓取数据。我可以使用它,它将带我到一个URL,但是我需要将GET数据放入URL中,并且必须有空格。我不知道如何在不将空格转换为%20的情况下保留空格。
我要使用的GET数据的格式如下:2018年8月23日(星期四)
theURL = theBeginning & "?startDate=" & chosenMonth & " " & chosenDay & ", 2018 (" & chosenDate & ")"
截至目前,这将以Aug%2023,%202018%20(Thu)的形式发送至浏览器,并在其网站上引发错误。
答案 0 :(得分:0)
我确定可能有更简单的方法,但是我创建了JavaScript
<form name = "myForm" method = "POST" action = "">
<input type = "text" name = "myURL" id = "myURL" />
</form>
<script>
t1 = window.setTimeout(function redirURL() { window.location = document.getElementById("myURL").value; },1000);
</script>
然后在VBA中通过它向我传递网址
Dim ieApp As InternetExplorer
Dim ieDoc As Object
Set ieApp = New InternetExplorer
ieApp.Navigate "myJavaScriptPage.htm"
Do While ieApp.Busy: DoEvents: Loop
Do Until ieApp.ReadyState = READYSTATE_COMPLETE: DoEvents: Loop
Set ieDoc = ieApp.Document
With ieDoc.forms(0)
.myURL.Value = theURL
End With
Do While ieApp.Busy: DoEvents: Loop
Do Until ieApp.ReadyState = READYSTATE_COMPLETE: DoEvents: Loop
With ieDoc.forms(0)
.myURL.Value = theURL
我必须在JavaScript中设置至少1秒钟的超时时间,否则它将尝试在VBA填入输入框之前进行重定向。我将尝试将URL复制到剪贴板,然后粘贴到IE的地址栏,但这目前对我来说有效。