1、可以使用`yield scrapy.FormRequest(url,formdata,callback)`方法发送POST请求。

 其中构造参数formdata可以是字典,也可以是可迭代的(key,value)元组,代表着需要提交的表单数据。

2、如果希望程序执行一开始就发送POST请求,可以重写Spider类的`start_requests(self)`方法,并且不再调用start_urls里的url。

import scrapy

class PostSpider(scrapy.Spider):
name = 'post'
allowed_domains = ['http://fanyi.youdao.com/']
start_urls = ['http://http://fanyi.youdao.com//'] #如果想要爬虫在一开始的时候就发送post请求,那么就需要在爬虫类中重写start_requests(self)方法,
#并且不再调用start_urls里面的url,如果不重写start_requests(self)那么爬虫会自动获取start_urls里面的url def start_requests(self):
url="http://fanyi.youdao.com/translate?smartresult=dict&smartresult=rule"
formdata = {
"i": "狗",
"from": "AUTO",
"to": "AUTO",
"smartresult": "dict",
"client": "fanyideskweb",
"salt": "16126984518491",
"sign": "32f75e6c239f04d7c8c61d9e8abeb677",
"ts": "1612698451849",
"bv": "6a1ac4a5cc37a3de2c535a36eda9e149",
"doctype": "json",
"version": "2.1",
"keyfrom": "fanyi.web",
"action": "FY_BY_REALTlME"
}
yield scrapy.FormRequest(url=url,formdata=formdata,callback=self.parse) def parse(self, response):
print('*'*20)
print(response.text)
print('*'*20)

最新文章

  1. 【jQuery】Jquery.cookie()
  2. POJ 2955 Brackets(区间DP)
  3. 为什么不能把委托(delegate)放在一个接口(interface)当中?
  4. 一些有用的UtilityExtend小方法
  5. SQL数据库基础(三)
  6. hdu----(5023)A Corrupt Mayor's Performance Art(线段树区间更新以及区间查询)
  7. nginx软负载的搭建
  8. 7. 泛化(Generalization)
  9. U-Boot--配置过程分析
  10. IOS开发的内存管理
  11. 微信小程序之----video视频播放
  12. sticky footer布局,定位底部footer
  13. allegro把formate symbol文件从一个文件拷入另一个文件的方法
  14. 736. Parse Lisp Expression
  15. Python 基于python操纵redis入门介绍
  16. 有多个.h引用时,不能有using namespace std
  17. ES5新增数组方法
  18. [From WIKI] IBM Z
  19. windows7文件共享 详细步骤 图解
  20. hbase源码系列(十三)缓存机制MemStore与Block Cache

热门文章

  1. .Net Core IIS部署以及问题总结
  2. 3D建模零代码平台
  3. CF845F - Guards In The Storehouse
  4. 【前端】js实现图片自适应
  5. SystemVerilog Tutorial
  6. Python elasticsearch 使用心得
  7. [网鼎杯2020]boom
  8. CF1764G1 题解
  9. golang 中使用mysql报错:“ scannable dest type slice with >1 columns (4) in result”
  10. 微信开发获取code的时候总是提示 10003 redirect_uri域名与后台配置不一致