H
H
Hector Synchrome2021-06-06 17:50:59
Python
Hector Synchrome, 2021-06-06 17:50:59

How to get https redirect link in get request?

I get a link (1), going to which there is a 5-second check, after which - a redirect to another link (2). Using the telethon library, I wrote the following code:

r = requests.get(url1, allow_redirects=True)
print(f'Чистая ссылка: {r.url}')

The result returns the reference (1) that was originally there. How do I get the link (2) in the script?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vindicar, 2021-06-06
@MatewGreg

> jumping to which the 5 second check occurs
This means that the redirect is done by means of JS, and not through HTTP 3XX response codes.
requests can only handle the last option, since it doesn't emulate the entire browser.
Theoretically, the correct link can be scratched out of the contents of the downloaded page, but in practice it is not a fact - most likely, the verification page was entered just to protect against scripts like yours.
You can play around with the selenium package, it allows you to pretend to be a full-fledged browser - suddenly it works out.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question