dimanche 8 mars 2020

Translating an Ajax request in Python

Hi guys i have this kind of web request that give me back some results. I need to take the results via python This is the Ajax code:

 function getInfoPaline(palina){
    $("#txtDisplay").html("<b> Recupero informazioni in corso...</b>");
    $.ajax({ 
        type: "POST", 
        contentType: "application/json; charset=utf-8", 
        url: "http://srv.anm.it/ServiceInfoAnmLinee.asmx/CaricaPrevisioni", 
        dataType: "json", 
        data: "{'Palina':'" + palina + "', 'key':'"+key_anm+"'}", 
        success: function (data) {
                var resp = "<table class='display'>";
                resp=resp + "<tr><td><font color='red'>Palina "+palina+"</font></td></tr>";
                resp=resp + "<tr><td><hr></td></tr>";
                $.map(data.d, function (item) { 
                    if (item.stato) {
                        resp = resp + "<tr><td><b>Nessuna informazione alla fermata</b></td></tr>";
                    } else {
                        var classe = "";
                        var in_arr = "";
                        if (item.timeMin < 3) {classe = "blink_me";in_arr = "<font color='red'><- in arr.</font>";}

And this is what i have tried , but it doesn't work:


# importing the requests library
import requests

# api-endpoint
key="6E60E894387A80AE90A8D4CD5BAF7DE8467A8955F7EBD9979225DA1DE9488E3057FB9330C9DCDA9597BCA3583DCC3985FFF91521618A025BD7C19487DBD5FA62"
URL = "http://srv.anm.it/ServiceInfoAnmLinee.asmx/CaricaPrevisioni"

# location given here
location = "2054"

# defining a params dict for the parameters to be sent to the API
PARAMS = {'Palina':location,'key':key}

# sending get request and saving the response as response object
r = requests.get(url = URL, params = PARAMS)

# extracting data in json format
data = r.json()








Aucun commentaire:

Enregistrer un commentaire