title: Fill-out HTML form and submit GET request Python 3
body: <p>Hi Python enthusiasts,</p>
  
  <p>I am struggling passing arguments using <em>urllib.request</em> in Python 3 to fill-out and submit a HTML form.</p>
  
  <p>The critical part of the html code looks something like:</p>
  
  <pre><code>&lt;H1&gt;Header&lt;/H1&gt;
  &lt;form method="get" action="/bin/formula.php"&gt;
  &lt;ul&gt;
   &lt;li&gt;Overview &lt;A HREF="/kathegory.php"&gt;Kathegory&lt;/A&gt; 
   &lt;li&gt;&lt;A HREF="/bin/search.php"&gt;Search&lt;/A&gt;
   &lt;li&gt;&lt;A HREF="/bin/formula.php"&gt;Formula&lt;/A&gt;
  &lt;li&gt;go to:
    &lt;input type="text" name="id" size=10 maxlength=10&gt;
    &lt;input type="submit" value="go"&gt;**
  &lt;/ul&gt;
  &lt;/form&gt;
  &lt;ul&gt;
   &lt;li&gt;&lt;A HREF="history.php"&gt;History&lt;/A&gt;
  &lt;/ul&gt;
  &lt;P&gt;
  &lt;HR&gt;
  </code></pre>
  
  <p>When filling-out the form manually on the website (e.g. <em>1</em>) <strong><a href="http://example.com" rel="nofollow noreferrer">http://example.com</a></strong>, the resulting page would be called <strong><a href="http://example.com/bin/formula.php?id=1" rel="nofollow noreferrer">http://example.com/bin/formula.php?id=1</a></strong></p>
  
  <p>My approach in Python so far was:</p>
  
  <pre><code>from bs4 import BeautifulSoup
  import urllib.request
  import urllib.parse
  
  
  h = {'User-agent': 'Mozilla/4.0 (compatible; MSIE 5.5; Windows NT)'}
  payload = {'id': '1'}
  url = 'http://example.com'
  
  data = urllib.parse.urlencode(payload)
  #data = data.encode('ascii') # data should be bytes
  req = urllib.request.Request(url, data, h)
  print(req.__dict__)
  
  with urllib.request.urlopen(req) as response:
  the_page = response.read()
  
  print(the_page)
  </code></pre>
  
  <p>without success.</p>
  
  <p>Any advice from more experienced users is very much appreciated!</p>
  
  <p>Cheers </p>