Submitting to a web form using python

前端 未结 3 1690
灰色年华
灰色年华 2020-12-01 07:44

I have seen questions like this asked many many times but none are helpful

Im trying to submit data to a form on the web ive tried requests, and urllib and none have

3条回答
  •  孤城傲影
    2020-12-01 08:16

    import urllib
    import urllib2
    
    url = 'http://www.someserver.com/cgi-bin/register.cgi'
    values = {'name' : 'Michael Foord',
          'location' : 'Northampton',
          'language' : 'Python' }
    
    data = urllib.urlencode(values)
    req = urllib2.Request(url, data)
    response = urllib2.urlopen(req) 
    the_page = response.read()
    

    This makes a POST request with the data specified in the values. we need urllib to encode the url and then urllib2 to send a request.

提交回复
热议问题