Python爬虫中请求实现岗位请求的案例

  介绍

这篇文章主要介绍Python爬虫中请求实现岗位请求的案例,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!

文章请求来说,我们一般需要为它增加一些参数。那么最基本的传参方法可以利用数据这个参数。

import 请求   ,   payload =, {& # 39; key1& # 39;:, & # 39; value1 # 39;,, & # 39; key2& # 39;:, & # 39; value2 # 39;}   时间=r  requests.post (“http://httpbin.org/post",, data=https://www.yisu.com/zixun/payload)   打印r。文本

{   “args"才能:,{},   “data"才能:,““,   “files"才能:,{},   “form"才能:,{   ,,,“key1":,“value1"   ,,,“key2":,“value2"   ,,},   “headers"才能:,{   ,,,“Accept":,“*/*“,   ,,,“Accept-Encoding":,“gzip、, deflate"   ,,,“Content-Length":,“23”,   ,,,“Content-Type":,“应用程序/x-www-form-urlencoded"   ,,,“Host":,“httpbin.org"   ,,,“User-Agent":,“python-requests/2.9.1"   ,,},   “json"才能:,空,   “url"才能:,“http://httpbin.org/post"   }

JSON格式的数据过去,所以我们可以用JSON。转储()方法把表单数据序列化。

import  json   import 请求   ,   时间=url  & # 39; http://httpbin.org/post& # 39;   payload =,{& # 39;一些# 39;:,& # 39;数据# 39;}   时间=r  requests.post (url, data=https://www.yisu.com/zixun/json.dumps(载荷))   打印r。文本

{   “args"才能:,{},   “data"才能:,“{\“\”:,\“数据\“}”,   “files"才能:,{},   “form"才能:,{},   “headers"才能:,{   ,,,“Accept":,“*/*“,   ,,,“Accept-Encoding":,“gzip、, deflate"   ,,,“Content-Length":,“16“,   ,,,“Host":,“httpbin.org"   ,,,“User-Agent":,“python-requests/2.9.1"   ,,},   “json"才能:,{   ,,,“some":,“data"   ,,},,   “url"才能:,“http://httpbin.org/post"   }

POST JSON格式的数据如果想要上传文件,那么直接用文件参数即可新建一个。txt的文件,内容写世界上你好!

 {
  “args"才能:,{},
  “data"才能:,““,
  “files"才能:,{
  ,,,“file":,“Hello 世界!“
  ,,},
  “form"才能:,{},
  “headers"才能:,{
  ,,,“Accept":,“*/*“,
  ,,,“Accept-Encoding":,“gzip、, deflate"
  ,,,“Content-Length":,“156”,
  ,,,“Content-Type":,“多部分/格式;,边界=7 d8eb5ff99a04c11bb3e862ce78d7000"
  ,,,“Host":,“httpbin.org"
  ,,,“User-Agent":,“python-requests/2.9.1"
  ,,},
  “json"才能:,空,
  “url"才能:,“http://httpbin.org/post"
  }

请求是支持流式上传的,这允许你发送大的数据流或文件而无需先把它们读入内存。要使用流式上传,仅需为你的请求体提供一个类文件对象即可

with 开放(& # 39;massive-body& # 39;), as  f:   requests.post (& # 39; http://some.url/streamed& # 39;,, data=https://www.yisu.com/zixun/f)

以上是Python爬虫中请求实现岗位请求的案例的所有内容,感谢各位的阅读!希望分享的内容对大家有帮助,更多相关知识,欢迎关注行业资讯频道!

Python爬虫中请求实现岗位请求的案例