简体   繁体   中英

How would I send and request data to a web server using python?

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>

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM