python scrapy模拟登录的方法
1、requests模块。直接携带cookies请求页面。
找到url,发送post请求存储cookie。
2、selenium(浏览器自动处理cookie)。
找到相应的input标签,输入文本,点击登录。
3、scrapy直接带cookies。
找到url,发送post请求存储cookie。
# -*- coding: utf-8 -*- import scrapy import re class GithubLoginSpider(scrapy.Spider): name = 'github_login' allowed_domains = ['github.com'] start_urls = ['https://github.com/login'] def parse(self, response): # 发送Post请求获取Cookies authenticity_token = response.xpath('//input[@name="authenticity_token"]/@value').extract_first() utf8 = response.xpath('//input[@name="utf8"]/@value').extract_first() commit = response.xpath('//input[@name="commit"]/@value').extract_first() form_data = { 'login': 'pengjunlee@163.com', 'password': '123456', 'webauthn-support': 'supported', 'authenticity_token': authenticity_token, 'utf8': utf8, 'commit': commit} yield scrapy.FormRequest("https://github.com/session", formdata=form_data, callback=self.after_login) def after_login(self, response): # 验证是否请求成功 print(re.findall('Learn Git and GitHub without any code!', response.body.decode()))
微信扫描下方的二维码阅读更多精彩内容
每日分享到群里,或者推荐给朋友会得大量积分,机会可以兑换微信零钱红包,具体请点击这里,得到了微信红包可以用来支持大飞哥
大飞哥能不能加鸡腿就看各位了!
开发者微信
开发者微信反馈BUG或者VIP可以添加,其他情况反馈可能不及时,见谅
版权声明
初衷是提供高清手机电脑壁纸等图片素材免费分享下载,禁止商用。图片素材来源网络,版权归原作者所有,若有侵权问题敬请告知我们!
【友情提醒】:
因平台原因不易展示大尺度写真,有的写真展示越少代表此套写真越性感,特别是xiuren等写真每一套写真完整套图50-100张不等。更多内容的欣赏请移步 点击这里
【更多图集移步】:
每日更新-点击这里
漂亮小姐姐-点击这里
性感美女-点击这里
清纯女孩-点击这里
xiuren专栏-点击这里
整站资源下载-点击这里