无法在 Excel VBA 中使用 XMLHTTP GET 请求从结束 URL 获取响应

Unable to get response from end url using XMLHTTP GET request in Excel VBA

提问人:Sourav 提问时间:12/22/2022 最后编辑:Sourav 更新时间:12/24/2022 访问量:265

问:

我正在尝试使用 excel vba xmlhttp GET 方法从 Web 检索表。 当我发送结束url(即)时,在发送反向链接url(ie)后,显示错误输出HTTP状态405。请帮忙。Url_Sub2Url_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

Output required table Initiator from network tools Getting response from URLUrl_Sub1 HTTP Status error 405 XMLHTTP GET request for Url_Sub2 Network tools

JavaScript VBA XML 解析 XMLHTTPREQUEST

评论

0赞 QHarr 12/23/2022
它不是显示在上面显示的请求链的底部吗?
0赞 Sourav 12/23/2022
是的,如何检索表?发送后无法直接发送“GET”。我缺少 JavaScript 发送查询的中间步骤,之后它会导致信息的存储位置。信息表是附件 image1 @QHarrUrl_Sub1Url_MainUrl_Sub1
0赞 QHarr 12/23/2022
为什么不能直接将 GET 发送到链中的结束 url?你试过了吗?
0赞 Sourav 12/23/2022
我尝试直接发送结束 url,但它返回错误:HTTP 状态 405 ?方法不允许 类型 状态报告 消息 访问被拒绝 描述 在请求行中接收的方法为源服务器所知,但目标资源不支持。@QHarrUrl_Sub1
0赞 QHarr 12/23/2022
www1.nseindia.com/products/dynaContent/common/......

答: 暂无答案