【说站】python scrapy.Request发送请求的方式
2023-06-13 09:13:17 时间
python scrapy.Request发送请求的方式
说明
1、使用scrapy.Request()指定method,body参数发送post请求。
2、使用scrapy.FormRequest()发送post请求,也可以发送表格和ajax请求。
实例
import scrapy
class Git2Spider(scrapy.Spider):
name = 'git2'
allowed_domains = ['github.com']
start_urls = ['http://github.com/login']
def parse(self, response):
username = 'GitLqr'
password = 'balabala'
# 从登录页面响应中解析出post数据
token = response.xpath('//input[@name="authenticity_token"]/@value').extract_first()
post_data = {
'commit': 'Sign in',
'authenticity_token': token,
'login': username,
'password': password,
'webauthn-support': 'supported',
}
print(post_data)
# 针对登录url发送post请求
yield scrapy.FormRequest(
url='https://github.com/session',
callback=self.after_login,
formdata=post_data
)
def after_login(self, response):
yield scrapy.Request('https://github.com/GitLqr', callback=self.check_login)
def check_login(self, response):
print(response.xpath('/html/head/title/text()').extract_first())
以上就是python scrapy.Request发送请求的方式,希望对大家有所帮助。更多Python学习指路:python基础教程
本文教程操作环境:windows7系统、Python 3.9.1,DELL G3电脑。
收藏 | 0点赞 | 0打赏
相关文章
- Python 编程 | 连载 03 - 布尔、列表和元组类型
- 苹果电脑python官网下载步骤-Python下载和安装图文教程[超详细]
- python编程是什么-Python编程
- python爬虫—–Python访问http的几种方式「建议收藏」
- java与python-如何对比Python和Java,只需三分钟告诉你!
- Python元组_python输出元组
- python2装饰器_python内置装饰器
- Python元组_python元组的定义方式
- Python编程运算符 比较运算符
- 【说站】Python unittest有哪些使用方法
- 【说站】python循环遍历如何理解
- python zipfile_Python 学习入门(16)—— zipfile
- python解析邮件
- python chmod_Python os.chmod用法及代码示例
- 【Python深度学习之路】-4 监督学习
- python如何生成随机数_Python生成50个随机数
- Python中使用数据类型进行转换命令
- [Python图像处理] 十六.图像的灰度非线性变换之对数变换、伽马变换
- 当Python也来进行修图神器,发现是真的蛮好用的呢!!
- PyQt5可编辑下拉框(comboBox):editable - python TCP服务器v1.5 - 客户端连接界面增加自定义参数(设置超时, 连接地址可选)
- 狂揽两千星,速度百倍提升,高性能Python编译器Codon开源
- python之os模块详解编程语言
- Python dict字典copy()方法详解
- Python与MongoDB 无缝连接(python连接mongodb)
- python用Redis与Python实现大数据收集与分析(redis 联合)
- python快速排序代码
- 使用nodejs、Python写的一个简易HTTP静态文件服务器