scrapy中发送post请求
2024-10-21 13:13:46
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)
最新文章
- 【jQuery】Jquery.cookie()
- POJ 2955 Brackets(区间DP)
- 为什么不能把委托(delegate)放在一个接口(interface)当中?
- 一些有用的UtilityExtend小方法
- SQL数据库基础(三)
- hdu----(5023)A Corrupt Mayor's Performance Art(线段树区间更新以及区间查询)
- nginx软负载的搭建
- 7. 泛化(Generalization)
- U-Boot--配置过程分析
- IOS开发的内存管理
- 微信小程序之----video视频播放
- sticky footer布局,定位底部footer
- allegro把formate symbol文件从一个文件拷入另一个文件的方法
- 736. Parse Lisp Expression
- Python 基于python操纵redis入门介绍
- 有多个.h引用时,不能有using namespace std
- ES5新增数组方法
- [From WIKI] IBM Z
- windows7文件共享 详细步骤 图解
- hbase源码系列(十三)缓存机制MemStore与Block Cache
热门文章
- .Net Core IIS部署以及问题总结
- 3D建模零代码平台
- CF845F - Guards In The Storehouse
- 【前端】js实现图片自适应
- SystemVerilog Tutorial
- Python elasticsearch 使用心得
- [网鼎杯2020]boom
- CF1764G1 题解
- golang 中使用mysql报错:“ scannable dest type slice with >;1 columns (4) in result”
- 微信开发获取code的时候总是提示 10003 redirect_uri域名与后台配置不一致