Web Cookies

Post your Gambas programming questions here.
Post Reply
Online
User avatar
cogier
Site Admin
Posts: 1127
Joined: Wednesday 21st September 2016 2:22pm
Location: Guernsey, Channel Islands

Web Cookies

Post by cogier »

Does anybody know how to deal with web cookies. If I navigate to Google Maps and select 'Accept All' button, how do I prevent having to do this every time the program runs? I have attached a little program that will stop after you click the 'Accept All' button and the screen has finished displaying the map, but there are no cookies!
WebCookies-0.0.1.tar.gz
(7.83 KiB) Downloaded 52 times
User avatar
BruceSteers
Posts: 1578
Joined: Thursday 23rd July 2020 5:20pm
Location: Isle of Wight
Contact:

Re: Web Cookies

Post by BruceSteers »

hmm can't figure that one out m8, cookies seem to remain null.

But i figured out a bypass.

I tried to download the url using HttpClient.Download() then the text i got was a page saying "Page moved to <url>" and clicking that url showed the page without the cookie request.
With this URL...
https://consent.google.com/ml?continue= ... l=en&src=1

So i broke down the url to make the following function that you can pass the map coords to..


Public Sub Form_Load()

  WebView1.Url = GetMappAdress("50.6945657,-1.2873369,12z")

End

Public Sub GetMappAdress(Address As String) As String
  
  Return "https://consent.google.com/ml?continue=https://www.google.com/maps/@" & 
  Address & 
  "&gl=GB&m=0&pc=m&uxe=eomtm&cm=2&hl=en&src=1"
  
End


That now loads the map and does not ask for cookie consent.

Ps. i tried playing around removing some of the url post fields "&gl=GB&m=0&pc=m&uxe=eomtm&cm=2&hl=en&src=1" but any changes seemed to break it.
Attachments
WebCookies-0.0.1.tar.gz
(53.01 KiB) Downloaded 44 times
If at first you don't succeed , try doing something differently.
BruceS
Online
User avatar
cogier
Site Admin
Posts: 1127
Joined: Wednesday 21st September 2016 2:22pm
Location: Guernsey, Channel Islands

Re: Web Cookies

Post by cogier »

Thanks, Bruce. I'll check it out.
User avatar
BruceSteers
Posts: 1578
Joined: Thursday 23rd July 2020 5:20pm
Location: Isle of Wight
Contact:

Re: Web Cookies

Post by BruceSteers »

Ps. you can see my house from there ;) lol
If at first you don't succeed , try doing something differently.
BruceS
User avatar
BruceSteers
Posts: 1578
Joined: Thursday 23rd July 2020 5:20pm
Location: Isle of Wight
Contact:

Re: Web Cookies

Post by BruceSteers »

Here's a different version that may work better in other locations as i'm not sure how important the properties of the post args are.

This version does in code what i originally did, it uses HttpClient.Download to fetch the url and then extracts the link from the page...


Public Sub Form_Open()

  Me.H = Desktop.H
  Me.W = Desktop.W / 2
  Me.X = Desktop.W / 2
  Me.Y = 0

  WebView1.Url = GetMappAdress("https://www.google.com/maps/@50.6945657,-1.2873369,12z")

End

Public Sub GetMappAdress(Address As String) As String

  Dim sHtml As String = HttpClient.Download(Address)  ' get the page

  Dim iStartPos As Integer = InStr(sHtml, "HREF=\"") + 6  ' extract the link
  sHtml = Mid(sHtml, iStartPos, InStr(sHtml, "\">", iStartPos) - iStartPos)

  sHtml = Replace(sHtml, "amp;", "") ' convert &amp; to just &

  Return sHtml

End
If at first you don't succeed , try doing something differently.
BruceS
Post Reply