Python爬虫 ruquests库的几种方法

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_40390825/article/details/82596935

 post函数

>>> payload = {'key1':'value1','key2':'value2','key3':'value3'}
>>> r = requests.post('http://httpbin.org/post', data = payload)
>>> print(r.text)
{
  "args": {}, 
  "data": "", 
  "files": {}, 
  "form": {
    "key1": "value1", 
    "key2": "value2", 
    "key3": "value3"
  }, 
  "headers": {
    "Accept": "*/*", 
    "Accept-Encoding": "gzip, deflate", 
    "Connection": "close", 
    "Content-Length": "35", 
    "Content-Type": "application/x-www-form-urlencoded", 
    "Host": "httpbin.org", 
    "User-Agent": "python-requests/2.19.1"
  }, 
  "json": null, 
  "origin": "112.8.128.83", 
  "url": "http://httpbin.org/post"
}

>>> 
>>> r = requests.post('http://httpbin.org/post', data = "ABC")
>>> print(r.text)
{
  "args": {}, 
  "data": "ABC", 
  "files": {}, 
  "form": {}, 
  "headers": {
    "Accept": "*/*", 
    "Accept-Encoding": "gzip, deflate", 
    "Connection": "close", 
    "Content-Length": "3", 
    "Host": "httpbin.org", 
    "User-Agent": "python-requests/2.19.1"
  }, 
  "json": null, 
  "origin": "112.8.128.83", 
  "url": "http://httpbin.org/post"
}

猜你喜欢

转载自blog.csdn.net/qq_40390825/article/details/82596935