0

I'm trying to get the source-code of a website: "https://004.lmvz.ch/disdonc/block/5d3f06e7f323590019034257/test?identifier=004lmvzch-disdonc-5d3f06e7f323590019034257&identifier=004lmvzch-disdonc-5d3f06e7f323590019034257". But if I'm trying it with requests:

import requests
url = "https://004.lmvz.ch/disdonc/block/5d3f06e7f323590019034257/test?identifier=004lmvzch-disdonc-5d3f06e7f323590019034257&identifier=004lmvzch-disdonc-5d3f06e7f323590019034257"
print(requests.get(url).text)

But it returns the sourcecode of the login page: "https://login.lmvz.ch", so I think I get redirected. How can I bypass this? I tried it with: allow_redirects=False, but it does still not work.

Greetings, Dave

Genius1512
  • 25
  • 3

1 Answers1

0

It's because it requires authentication info, the website automatically redirects to login page if you don't provide it.

Solution:

  1. Login with valid credentials
  2. Get the authen session info
  3. Add authen info to header (in cookie) to request.

Check it out: How to send cookies in a post request with the Python Requests library?

lucas-nguyen-17
  • 5,516
  • 2
  • 9
  • 20