Submitting to a web form using python

前端 未结 3 1686
灰色年华
灰色年华 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:38

    If you want to pass q as a parameter in the URL using requests, use the params argument, not data (see Passing Parameters In URLs):

    r = requests.get('http://stackoverflow.com', params=data)
    

    This will request https://stackoverflow.com/?q=%5Bpython%5D , which isn't what you are looking for.

    You really want to POST to a form. Try this:

    r = requests.post('https://stackoverflow.com/search', data=data)
    

    This is essentially the same as GET-ting https://stackoverflow.com/questions/tagged/python , but I think you'll get the idea from this.

提交回复
热议问题