gpt4 book ai didi

excel - 如何使用excel vba获取cookie信息

转载 作者:行者123 更新时间:2023-12-04 22:20:24 39 4
gpt4 key购买 nike

我正在尝试从 Network --> RequestHeader 下面页面 https://www.nseindia.com/market-data/equity-derivatives-watch 下获取 cookie 信息
我从下面的代码中得到的只是响应 header “set-cookie”,但我需要请求 header 下的“cookie”信息。下面是我尝试过的代码。

Function GetCookie(strUrl)
With CreateObject("WinHttp.WinHttpRequest.5.1")
.Open "GET", strUrl, False
.SetRequestHeader "REFERER", strUrl
.SetRequestHeader "User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)"
.SetRequestHeader "Accept", "text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5"
.SetRequestHeader "Accept-Language", "en-us,en;q=0.5"
.SetRequestHeader "Accept-Charset", "ISO-8859-1,utf-8;q=0.7,*;q=0.7"
.Send
strCookie = .GetAllResponseHeaders

strCookie = Split(strCookie, vbCrLf)

Debug.Print strCookie

' strCookie = Split(strCookie, ";")(0)
' GetCookie = strCookie
End With
End Function



Sub Demo()
Debug.Print GetCookie("https://www.nseindia.com/market-data/equity-derivatives-watch")
End Sub
我需要以下 cookie 信息
enter image description here

最佳答案

问题是 cookie 每 1 小时过期一次,所以我们必须刷新它们。

Function GetCookie(strUrl)
With CreateObject("WinHttp.WinHttpRequest.5.1")
.Open "GET", strUrl, False
.SetRequestHeader "REFERER", strUrl
.SetRequestHeader "User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)"
.SetRequestHeader "Accept", "text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5"
.SetRequestHeader "Accept-Language", "en-us,en;q=0.5"
.SetRequestHeader "Accept-Charset", "ISO-8859-1,utf-8;q=0.7,*;q=0.7"
.Send
strCookie = .getAllResponseHeaders
strCookie = Split(strCookie, vbCrLf)
GetCookie = Trim(Split(Split(strCookie(5), ";")(0), ":")(1)) & "; " & Trim(Split(Split(strCookie(6), ";")(0), ":")(1))
End With
End Function

Sub get_cookies()
Msgbox(GetCookie("https://www.nseindia.com/market-data/equity-derivatives-watch"))
End Sub
试试这个,它会返回 nsit 和 nseappid (Eg:- nsit=zk3-uf45niHVOsW_yaK2kIdWg; nseappid=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiONKJklmlmNIOJkjnkoivhvIiwiYXVkIjoiYXBpLm5zZSIsImlhdCI6MTVHJVHuihnjyuGyufhJNkoioxNjEzNjI3MjMyfQ.PDBf7k6fGsYicbM7sYeJrhE0OtGENf_e5YdRENkAHq0)为我工作,我已经自动化了。
我们需要 cookie 的链接是 NSE 站点,而不是特定的罢工或脚本。

关于excel - 如何使用excel vba获取cookie信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64292885/

39 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com