提问人:Sourav 提问时间:12/22/2022 最后编辑:Sourav 更新时间:12/24/2022 访问量:265
无法在 Excel VBA 中使用 XMLHTTP GET 请求从结束 URL 获取响应
Unable to get response from end url using XMLHTTP GET request in Excel VBA
问:
我正在尝试使用 excel vba xmlhttp GET 方法从 Web 检索表。
当我发送结束url(即)时,在发送反向链接url(ie)后,显示错误输出HTTP状态405。请帮忙。Url_Sub2
Url_Main
Option Explicit
Dim xmlhttp As New MSXML2.XMLHTTP60,html As New HTMLDocument
Dim sResp$, Url_Main$, Url_Sub1$, Url_Sub2$
Sub FetchHistoricalDataWorking()
'URL
Url_Main$ = "https://www1.nseindia.com/products/content/equities/equities/eq_security.htm"
Url_Sub1$ = "https://www1.nseindia.com/marketinfo/sym_map/symbolCount.jsp?symbol=LUPIN"
Url_Sub2$ = "https://www1.nseindia.com/products/dynaContent/common/productsSymbolMapping.jsp?symbol=LUPIN&segmentLink=3&symbolCount=2&series=ALL&dateRange=3month&fromDate=&toDate=&dataType=PRICEVOLUMEDELIVERABLE"
'XML Link
With xmlhttp
.Open "GET", Url_Main$, False '/products/content/equities/equities/eq_security.htm"
.setRequestHeader "User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36"
.setRequestHeader "Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9"
.setRequestHeader "Accept-Encoding", "gzip, deflate, br"
.setRequestHeader "Accept-Language", "en-IN,en-US;q=0.9,en;q=0.8"
.setRequestHeader "Cache-Control", "no-cache"
.setRequestHeader "Connection", "keep-alive"
.setRequestHeader "Host", "www1.nseindia.com"
.send
While .readyState < 4: DoEvents: Wend
.Open "GET", Url_Sub1$, False
.setRequestHeader "User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36"
.setRequestHeader "Referer", Url_Main$
.setRequestHeader "Accept", "*/*"
.setRequestHeader "Accept-Encoding", "gzip, deflate, br"
.setRequestHeader "Accept-Language", "en-IN,en-US;q=0.9,en;q=0.8"
.setRequestHeader "Cache-Control", "no-cache"
.setRequestHeader "Connection", "keep-alive"
.setRequestHeader "Host", "www1.nseindia.com"
.send
While .readyState < 4: DoEvents: Wend
.Open "GET", Url_Sub2$, False
.setRequestHeader "User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36"
.setRequestHeader "Referer", Url_Main$
.setRequestHeader "Accept", "*/*"
.setRequestHeader "Accept-Encoding", "gzip, deflate, br"
.setRequestHeader "Accept-Language", "en-IN,en-US;q=0.9,en;q=0.8"
.setRequestHeader "Cache-Control", "no-cache"
.setRequestHeader "Connection", "keep-alive"
.setRequestHeader "Host", "www1.nseindia.com"
.send
While .readyState < 4: DoEvents: Wend
sResp = .responseText
Debug.Print sResp
End With
html.body.innerHTML = sResp
' Debug.Print oHttp.readyState & oHttp.Status
End Sub
答: 暂无答案
评论
Url_Sub1
Url_Main
Url_Sub1
Url_Sub1