How to get cookie value using excel vba

amo

Board Regular
Joined
Apr 14, 2020
Messages
141
Office Version
  1. 2010
Platform
  1. Windows
I want to retrieve the cookie value using this code, but failed

VBA Code:
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/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-Language", "id-ID,id;q=0.9,en-US;q=0.8,en;q=0.7"
    .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.instagram.com"))
End Sub

Screenshot_1.png


this is the result

Screenshot_2.png



any idea ???
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
Sure. Your code expressly requests the fifth element of the array, which based on the outcome above, is the "accept" header. Try changing the 5 to a 9 in the strCookie array?
 
Upvote 0
Sure. Your code expressly requests the fifth element of the array, which based on the outcome above, is the "accept" header. Try changing the 5 to a 9 in the strCookie array?
you can try at your place
because I tried it didn't work
 
Upvote 0
Thank you ever so much for the offer of letting me help you, but no, I won't.
How about instead you provide some helpful detail as to what exactly you mean when you say "it didn't work". Was there an error message? What data, if any, did it return?
 
Upvote 0

Forum statistics

Threads
1,223,240
Messages
6,170,951
Members
452,368
Latest member
jayp2104

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top