title: Controlling website (html/javascript) through Python (jQuery/Ajax) without browser
body: <p>I am trying to write a small Python-script that opens/loads content from a website (no-browser) and changes values on the website. The website was obviously written for graphical user input through a webrowser, however I now need to change those values automatically and can no change those settings manually.</p>
  
  <p>Below you can find snippet examples for the corresponding HTML and javascript code that changes the values of the homepage. I extracted this code through the "code inspector" and don't have access to those.</p>
  
  <p>The website is running locally in my network through http:\*.<em>.</em>.*:8080 where <em>.</em>.<em>.</em> is my IP and 8080 is the port (both fixed).</p>
  
  <p>I assume that the following line is essential, however I'm unclear how to reproduce that with Python:</p>
  
  <pre><code> $.ajax(root+'/settings/' + control + '?set='+val).fail(display_error('cannot_set', control));
  </code></pre>
  
  <p>I was looking into several Python packages such as flask, http, request, however I haven't found a good answer how my problem can be solved.</p>
  
  <p>In the end, I'd like to have a Python method with a simple argument call close to this:</p>
  
  <pre><code>def change_crop_x(val):
     # Here needs to be the python code I'm unsure of
     return True # True if value was succesfully changed
  
  </code></pre>
  
  <p>Any help will be very much appreciated.</p>
  
  <p>Best,
  Florian</p>
  
  <pre><code>&lt;div class="form-group" id="crop_host"&gt;
    &lt;label class="col-xs-3 control-label"&gt;Crop&lt;/label&gt;
    &lt;div class="col-xs-4"&gt;
      &lt;label class="col-xs-2 nopadding" for="range_crop_x"&gt;X:&lt;/label&gt; &lt;input class="col-xs-10" id="range_crop_x" type="range" min="0" max="100" value="50"/&gt;
    &lt;/div&gt;
    &lt;div class="col-xs-4"&gt;
      &lt;label class="col-xs-2 nopadding" for="range_crop_y"&gt;Y:&lt;/label&gt; &lt;input class="col-xs-10" id="range_crop_y" type="range" min="0" max="100" value="50" /&gt;
    &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/Ly9JM.png" rel="nofollow noreferrer">Example of content to change</a></p>
  
  <pre><code>  var crops = ["crop_x", "crop_y"]
    var crop_holders = []
    for (i in crops) {
      var control = crops[i]
      crop_holders.push({
        val: get_val('#range_'+control),
        id: -9999,
        upd: function(val) {},
        cmd: function(control){ return function(val) {
          if (val == 0) {
            val = 1;
          }
          $.ajax(root+'/settings/' + control + '?set='+val).fail(display_error('cannot_set', control));
        }} (control)
      })
    }
  </code></pre>
  
  <pre><code>if (config.curvals.crop_x != undefined) {
        $('#range_crop_x')
          .val(config.curvals.crop_x)
          .change(scheduleUpdateW(crop_holders[0]));
        $('#range_crop_y')
          .val(config.curvals.crop_y)
          .change(scheduleUpdateW(crop_holders[1]));
      } else {
        $('#crop_host').hide()
      }
  </code></pre>