Python 官方文档:入门教程 => 点击学习
这篇文章主要讲解了“python scrapy.Request怎么发送请求”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习“Python scrapy.Request怎么发送请求”吧!说明使用s
这篇文章主要讲解了“python scrapy.Request怎么发送请求”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习“Python scrapy.Request怎么发送请求”吧!
说明
使用scrapy.Request()指定method,body参数发送post请求。
使用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 scrapy.Request怎么发送请求这一问题有了更深刻的体会,具体使用情况还需要大家实践验证。这里是编程网,小编将为大家推送更多相关知识点的文章,欢迎关注!
--结束END--
本文标题: python scrapy.Request怎么发送请求
本文链接: https://www.lsjlt.com/news/298175.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
下载Word文档到电脑,方便收藏和打印~
2024-03-01
2024-03-01
2024-03-01
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0