1

I've been trying to use the request library in order to send information to a web server. However, I have no clue what data to send to the server in order to log in. (This is my first time using requests and I was wondering if someone could help explain this to me) Edit: I'm trying to make it submit a username and password to the site.

My code:

import requests 

Sdata = {'username':'testingemail@gmail.com','password':'testing123','login':'submit'}

r = requests.post(url = 'https://gmchosting.com/billing/clientarea.php',data=Sdata) 

html = r.text 
print(html)

The Part of the website I want the file to communicate with:

<input type="hidden" name="token" value="003cc13dfa662dd183f098c2a2afc81331da0ba3" />
        <div class="form-group">
            <label for="inputEmail">Email Address</label>
            <input type="email" name="username" class="form-control" id="inputEmail" placeholder="Enter email" autofocus>
        </div>

        <div class="form-group">
            <label for="inputPassword">Password</label>
            <input type="password" name="password" class="form-control" id="inputPassword" placeholder="Password">
        </div>

        <div class="checkbox">
            <label>
                <input type="checkbox" name="rememberme" /> Remember Me
            </label>
        </div>

        <div align="center">
            <input id="login" type="submit" class="btn btn-primary" value="Login" /> <a href="pwreset.php" class="btn btn-default">Forgot Password?</a>
        </div>
    </form>

</div>
Nazim Kerimbekov
  • 4,712
  • 8
  • 34
  • 58
  • 2
    Are you getting an error? What you are doing looks correct. Though don't think you need the submit part. See this post: https://stackoverflow.com/questions/35569447/python-how-to-click-submit-button-in-a-form – Tim Feb 27 '19 at 22:26
  • 1
    Could it be that you want to start a session and then perform other requests? Check this post: https://stackoverflow.com/a/20760055/3751268 – aitorhh Feb 27 '19 at 22:28
  • try replacing `data=` with `json=` – Nazim Kerimbekov Feb 28 '19 at 10:30
  • You'll probably need to include the `token` in your payload as well, it looks like CSRF protection. – mfrackowiak Feb 28 '19 at 12:18
  • I'd suggest using RoboBrowser. https://robobrowser.readthedocs.io/en/latest/readme.html It Helps to manage tokens, cookies and so on, allowing you to concentrate on your actual work. – fernand0 Feb 28 '19 at 12:24

1 Answers1

0

You can use parameters in the url, like this:

https://google.com?myparameter=true

And you can get them using JS.

So, you can use:

import webbrowser
webbrowser.open('https://example.com?myparam=hello&hello=yeah')

And in the JS:

const params = new URLSearchParams(window.location.search);
const myparam = decodeURIComponent(urlp.get('myparam'));
alert(myparam)
Tiago Rangel
  • 1,159
  • 15
  • 29