简体   繁体   中英

Sending requests to webpages using Python

I need to send "M6" value to this http://wap2.mobi/votes/?id=16552 webpage using python. I have some problem to do that because the website submit the vlaue using javascripts.

This is the html source for the input:

<div id="info">
<input type="text" id="company" name="com" size="20">
<input type="button" value="Send Now" onClick="getData();"></div>
<div class="clearfix"></div>
</div>

and the js code is:

    function getData()
        {
        var Send = document.getElementById("company").value;
        $.ajax({
           type: "POST",
           url: "../votes/comments.php?id=97775547",
           data: "com="+Send,

           beforeSend: function() {
               $("div#info").html("<img src='../loading.gif'>loding...");
           },
       success: function(result)
       {

           $("div#info").html(result);
    }

     });
        }

Please if someone can help me with this.

Thank you.

You can use requests module for making this POST request in python.

import requests

url = "http://wap2.mobi/votes/"
payload = {'id': '16552'}
r = requests.post(url, params=payload)
print "url : ", r.url
print "response status code : ", r.status_code

So in response we get status 200. ( 200 means - The request has succeeded )

url : http://wap2.mobi/votes/?id=16552
response status code : 200

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