0

There's this site called https://coolors.co and I want to grab the color palettes they generate programmatically. In the browser, I just click the button "Start the generator!". The link the button is attached to is https://coolors.co/generate. If I go to that url in the browser, the color palette is generated. Notice, that the url is changed to https://coolors.co/092327-0b5351-00a9a5-4e8098-90c2e7 (that's an example - the last part of the url is just the hex codes). There is obviously a redirect.

But when I do this in Python with a get request, I am not redirected but stay on this intermediate site. When I look at r.text, it tells me "This domain doesn't exist and is for sale".

How do I fix this? How do I enable the redirect?

Here's the code:

url = 'https://coolors.co/generate'
headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.110 Safari/537.36'}
r = requests.get(url, headers=headers)

Thanks!

cedi123
  • 179
  • 1
  • 6

1 Answers1

0

This website does not use an HTTP redirect.

It probably uses a Javascript form of redirection like changing window.location.href, requests is not a browser so it does not execute the javascript in the page you requested hence the absence of redirection.

Speedlulu
  • 331
  • 2
  • 7
  • Can I somehow trigger that javascript? – cedi123 Jan 03 '22 at 16:07
  • The simple answer is no, the complicated one is you should not but you could look at this : https://stackoverflow.com/questions/10136319/executing-javascript-from-python. – Speedlulu Jan 03 '22 at 16:24