scrpy-cookie
两种方法模拟登陆
1.直接携带cookie
import re
import scrapy class RenrenSpider(scrapy.Spider):
name = 'renren'
allowed_domains = ['renren.com']
start_urls = ['http://renren.com/']
# 重写start_urls的处理方法,加上cookies
def start_requests(self):
cookies = '''anonymid=juzai6na-g0fmvf; depovince=GW; _r01_=1; ick_login=9de0dec9-4f94-42e0-819b-22df9e9adf66; ick=75ca63f4-c056-4af0-ba6e-7683bb07d04d;
jebecookies=747a7092-f53c-40ae-bc0b-90b3f9ab5e2d|||||; JSESSIONID=abcjUmG7wh1SragUBfEPw; _de=8B28AA93122391F898B641D1F469956B; p=9984be9e31957abbf89e6751ad2fd8f48;
first_login_flag=1; ln_uact=18781736136; ln_hurl=http://head.xiaonei.com/photos/0/0/men_main.gif; t=59071958da717542e6a80ffd0df189c38;
societyguester=59071958da717542e6a80ffd0df189c38; id=970578188; xnsid=a1ea20ee; ver=7.0; loginfrom=null;
jebe_key=ed626104-9dc0-45aa-961c-2cfea0e1935d%7C570ae1432b36360003bbd95b7fb6661a%7C1556356655118%7C1%7C1556356654129;
wp_fold=0; XNESSESSIONID=2d1bc0ef1740; vip=1'''
cookies = {i.split('=')[0]: i.split('=')[1] for i in cookies.split('; ')}
start_urls = ['http://www.renren.com/970578188/profile?v=info_timeline']
yield scrapy.Request(
start_urls[0],
callback=self.parse_detail,
cookies=cookies
) def parse_detail(self, response):
res = response.xpath("//div[@class='love-infobox']/p/text()").extract_first()
print(res)
# print(re.findall(r'单身', response.body.decode()))
2.找到发送post请求的url地址,带上信息,发送请求 。 scrapy.FormRequest
# 模拟github网登陆
class Renren1Spider(scrapy.Spider):
name = 'renren1'
allowed_domains = ['github.com']
start_urls = ['http://github.com/login']
# func 1
def parse(self, response):
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
post_data = dict(
login='tangpinggui',
password='***********',
authenticity_token=authenticity_token,
utf8=utf8,
commit=commit
)
yield scrapy.FormRequest(
url="https://github.com/session",
formdata=post_data,
callback=self.after_login
)
# func 2
def parse(self, response):
# 只需要登陆名及密码,其它form data数据由FormRequest.from_response 找到
post_data = dict(
login='tangpinggui',
password='*********',
)
yield scrapy.FormRequest.from_response(
response, # 自动从response找到form表单
formdata=post_data,
callback=self.after_login
) def after_login(self, response):
res = response.xpath("//a[@class='btn btn-outline mt-2']/text()").extract_first()
print(res)
# 模拟人人网网登陆
class Renren1Spider(scrapy.Spider):
name = 'renren1'
allowed_domains = ['renren.com']
start_urls = ['http://renren.com']
"""
email: 18781736136
icode:
origURL: http://www.renren.com/970578188/profile?v=info_timeline
domain: renren.com
key_id: 1
captcha_type: web_login
password: 6af626fe325aa7fcea5e6ff3c541404d9104667d6d941a5c5c30390c2d5da8ad
rkey: 86cfb8063d4b47d05407cc549819f975
f:
"""
# func 1
def parse(self, response):
origURL = response.xpath("//input[@name='origURL']/@value").extract_first()
domain = 'renren.com'
key_id = response.xpath("//input[@name='key_id']/@value").extract_first()
captcha_type = response.xpath("//input[@name='captcha_type']/@value").extract_first()
# rkey = response.xpath("//input[@name='rkey']/@value").extract_first()
post_data = dict(
email='1********',
password='**********',
origURL=origURL,
domain=domain,
key_id=key_id,
captcha_type=captcha_type,
# rkey='', #不知道怎么获取,貌似不要也能登录
f=''
)
yield scrapy.FormRequest(
url="http://www.renren.com/PLogin.do",
formdata=post_data,
callback=self.after_login
)
# func 2
def parse(self, response):
post_data = dict(
email='1********',
password='**************',
)
yield scrapy.FormRequest.from_response(
response, # 自动从response找到form表单中
formdata=post_data,
callback=self.after_login
) def after_login(self, response):
print('start....')
with open('renren.html', 'w') as f:
f.write(response.body.decode())
scrpy-cookie的更多相关文章
- 超大 Cookie 拒绝服务攻击
有没有想过,如果网站的 Cookie 特别多特别大,会发生什么情况? 不多说,马上来试验一下: for (i = 0; i < 20; i++) document.cookie = i + '= ...
- IE10、IE11 User-Agent 导致的 ASP.Net 网站无法写入Cookie 问题
你是否遇到过当使用一个涉及到Cookie操作的网站或者管理系统时,IE 6.7.8.9下都跑的好好的,唯独到了IE10.11这些高版本浏览器就不行了?好吧,这个问题码农连续2天内遇到了2次.那么,我们 ...
- 解决cookie跨域访问
一.前言 随着项目模块越来越多,很多模块现在都是独立部署.模块之间的交流有时可能会通过cookie来完成.比如说门户和应用,分别部署在不同的机器或者web容器中,假如用户登陆之后会在浏览器客户端写入c ...
- jquery插件的用法之cookie 插件
一.使用cookie 插件 插件官方网站下载地址:http://plugins.jquery.com/cookie/ cookie 插件的用法比较简单,直接粘贴下面代码示例: //生成一个cookie ...
- 一个诡异的COOKIE问题
今天下午,发现本地的测试环境突然跑不动了,thinkphp直接跑到异常页面,按照正常的排错思路,直接看thinkphp的log 有一条 [ error ] [2]setcookie() expects ...
- [转载]Cookie/Session的机制与安全
Cookie和Session是为了在无状态的HTTP协议之上维护会话状态,使得服务器可以知道当前是和哪个客户在打交道.本文来详细讨论Cookie和Session的实现机制,以及其中涉及的安全问题. 因 ...
- jquery.cookie的使用
今天想到了要为自己的影像日记增加赞的功能,并且需要用到cookie. 记得原生的js操作cookie也不是很麻烦的,但似乎jquery更简单,不过相比原生js,需要额外引入2个文件,似乎又不是很好,但 ...
- 跨域问题,前端主动向后台发送cookie
跨域是什么? 从一个域名的网页访问另一个域名的资源,就会出现跨域.只要协议.端口.域名有一个不同就会出现跨域 例如: 1.协议不同 http://www.baidu.com:80 和 https:/ ...
- 【流量劫持】沉默中的狂怒 —— Cookie 大喷发
精简版:http://www.cnblogs.com/index-html/p/mitm-cookie-crack.html 前言 上一篇文章 讲解了如何借助前端技术,打造一个比 SSLStrip 更 ...
- 好好了解一下Cookie
Cookie的诞生 由于HTTP协议是无状态的,而服务器端的业务必须是要有状态的.Cookie诞生的最初目的是为了存储web中的状态信息,以方便服务器端使用.比如判断用户是否是第一次访问网站.目前最新 ...
随机推荐
- CentOS7装好了开始装wrf了
1. 安装PGI编译器 下载地址:https://www.pgroup.com/products/community.htm(pgi官网社区版) 下载完将其复制到虚拟机内: 补充一下 我是在home ...
- 播放器: AVPlayer
AVPlayer *player = [AVPlayer playerWithURL:[NSURL URLWithString:@"http://flv2.bn.netease.com/vi ...
- Struts2 2.5版本的通配符和动态方法调用的问题
Struts2.5版本之后,使用通配符的时候出现错误 配置的四个action,使用通配符和动态方法的时候找不到其中的update方法后来经过查找才知道原来是版本加了一个 <action name ...
- DevExpress 控件汉化代码和使用方法
DevExpress 第三方控件汉化的全部代码和使用方法 DevExpress.XtraEditors.Controls 此控件包中包含的控件最多,包括文本框,下拉列表,按钮,等等 ...
- 深度系统 deepin 15.9 关闭桌面
深度系统 deepin 15.9 关闭桌面 由于特别的原因,关闭深度的桌面. sudo systemctl disable lightdm 如果需要在命令模式进入桌面可以使用以下命令. sudo se ...
- Dev GridControl数据修改后实时更新数据源(转)
1: /// <summary> 2: /// 嵌入的ComboxEdit控件选择值变化事件 3: /// </summary> 4: /// <param nam ...
- 常用git的命令
常用git的命令 详解git fetch与git pull的区别 Git放弃本地所有修改,强制更新: git fetch --all git reset --hard origin/master 说明 ...
- ThinkPHP 中使用 IS_AJAX 判断原生 JS 中的 Ajax 出现问题
问题: 在 ThinkPHP 中使用原生 js 发起 Ajax 请求的时候.在控制器无法使用 IS_AJAX 进行判断.而使用 jQuery 中的 ajax 是没有问题的. 在ThinkPHP中.有一 ...
- python基础知识9---字符串拼接,深浅拷贝,三元运算
一.字符串格式化 Python的字符串格式化有两种方式: 百分号方式.format方式 百分号的方式相对来说比较老,而format方式则是比较先进的方式,企图替换古老的方式,目前两者并存.[PEP-3 ...
- awk命令基本使用方法
awk命令 基本用法 awk '{print $1, $4}' netstat.txt 单引号中大括号的部分就是awk语句 $1至$n表示第几列,$0表示整行 格式化输出的方法 $ awk '{pri ...