dimanche 17 juin 2018

How to use a page redirect from python script?

I have an HTML page like this.

index.php

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Submit</title>
</head>
<body>

</body>
<script type="text/javascript">
    window.onload = function () {
        window.location.href = "http://127.0.0.1:3333/test.php";
    }
</script>
</html>

which means, If I load this page using my web browser, it will automatically get redirected to /test.php. I was running my server at http://127.0.0.1:3333 while testing. This bit is working as expected.

My question is how can I do the same thing using a python script?

This script using the requests module isn't working.

import requests
response = requests.get('http://127.0.0.1:3333')
print(response.text)

So, when I print out the value of response.text, I want to get the value of test.php. I've realised that the response module isn't the best way to do this. But what should I do and is this even possible?




Aucun commentaire:

Enregistrer un commentaire