python中scrapy怎么发送一个post请求

甜甜2312 2016-05-04 11:19:33
应该用scrapy.http中的Request 还是 FormRequest 我是新手 不太懂这边

我用Request是这样写的
Request("http://www.lagou.com/jobs/positionAjax.json?px=new",
body="first=true&kd=&pn=1"
meta={"first": True, "kd": "", "pn": 1},
method="POST",
callback=self.parse
)
我不知道body是干嘛的 也不知道meta是干嘛的 这样写本身没有问题
但是我翻页的时候发现pn是1或者2好像没差别 才知道这样是错误的

用FormRequest我也看了看
FormRequest(url="http://www.lagou.com/jobs/positionAjax.json?px=new",
callback=self.parse,
formdata={"first": True, "kd": "", "pn": page_num},
)
但是这样会报错

正常应该怎么写 希望大家帮忙解答一些 万分感谢
...全文
1974 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
luckystar1992 2016-07-06
  • 打赏
  • 举报
回复
dont_filter = True 不要做URL重复检测
qq_35462093 2016-06-29
  • 打赏
  • 举报
回复
你的问题解决了吗?
Abysman 2016-05-12
  • 打赏
  • 举报
回复
参数: url (string) – 请求的URL callback (callable) – the function that will be called with the response of this request (once its downloaded) as its first parameter. For more information see Passing additional data to callback functions below. If a Request doesn’t specify a callback, the spider’s parse() method will be used. Note that if exceptions are raised during processing, errback is called instead. method (string) – 此请求的HTTP方法。默认是 'GET'。 meta (dict) – Request.meta 属性的初始值。 一旦此参数被设置, 通过参数传递的字典将会被浅拷贝。 body (str or unicode) – request体。如果传进的参数是 unicode 类型,将会被编码为 str 类型。如果 body 参数没有给定,那么将会存储一个空的string类型,不管 这个参数是什么类型的,最终存储的都会是 str 类型(永远不会是 unicode 或是 None)。 headers (dict) – 请求头。字典值的类型可以是strings (for single valued headers) 或是 lists (for multi-valued headers)。如果传进的值是 None ,那么HTTP头将不会被发送。 cookies (dict or list) – 请求的cookies。可以被设置成如下两种形式。 参考http://scrapy-chs.readthedocs.io/zh_CN/latest/topics/request-response.html
甜甜2312 2016-05-04
  • 打赏
  • 举报
回复
有没有人啊 帮忙解答一下

37,721

社区成员

发帖
与我相关
我的任务
社区描述
JavaScript,VBScript,AngleScript,ActionScript,Shell,Perl,Ruby,Lua,Tcl,Scala,MaxScript 等脚本语言交流。
社区管理员
  • 脚本语言(Perl/Python)社区
  • IT.BOB
加入社区
  • 近7日
  • 近30日
  • 至今

试试用AI创作助手写篇文章吧