美文网首页
爬虫中的模拟登录

爬虫中的模拟登录

作者: 八神苍月 | 来源:发表于2017-06-12 00:04 被阅读47次

使用Fiddler 抓取网络数据,登录'https://www.v2ex.com/',抓到一堆包,使用find功能标记出'v2ex'的有用包,看它的cookies:

Paste_Image.png

可以发现最关键的那个HTTP会话包里面,
Request Count: 1
Bytes Sent: 1,185 (headers:1,185; body:0)
Bytes Received: 84,209 (headers:632; body:83,577)

点击Inspectors,查看核心参数。

代码如下:

import requests
from bs4 import BeautifulSoup
 
url = "http://www.v2ex.com/signin"
UA = "Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.13 Safari/537.36"
 
header = { "User-Agent" : UA,
           "Referer": "http://www.v2ex.com/signin"
           }
 
v2ex_session = requests.Session()
f = v2ex_session.get(url,headers=header)
 
soup = BeautifulSoup(f.content,"html.parser")
once = soup.find('input',{'name':'once'})['value']
print(once)
 
postData = { 'u': 'whatbeg',
             'p': '*****',
             'once': once,
             'next': '/'
             }
 
v2ex_session.post(url,
                  data = postData,
                  headers = header)
 
f = v2ex_session.get('http://www.v2ex.com/settings',headers=header)
print(f.content.decode())

这个网站早已改版了:
不过经过RSA加密后的数据也可以在Fiddler里面抓出来,
第一次请求的TextView 里面可以看到数据:
dea6a48e5539a63cb15c7ee309fbdf422a27b31a52a52a92ce188e7bca63de9e=your name&38fe18af1d70cea04c1f16c06106c1c529f65240f4e0ebaeb98ed02ba20026e4=your password&once=57443&next=%2F

dea6a48e5539a63cb15c7ee309fbdf422a27b31a52a52a92ce188e7bca63de9e是用户名的加密值
38fe18af1d70cea04c1f16c06106c1c529f65240f4e0ebaeb98ed02ba20026e4是密码的加密值
once是明文

代码如下:

import requests
import re
import json
from bs4 import BeautifulSoup
 
s = requests.Session()
 
headers = {
    'Accept': 'application/json, text/javascript, */*; q=0.01',
    'Referer': 'http://passport.cnblogs.com/user/signin',
    'User-Agent': 'Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36',
    'Cookie': '__gads=ID=fc58354935efbd89:T=1458638388:S=ALNI_MYEtsucyem4nWeL9mdxvQmfAZlTgQ; _ga=GA1.2.111229817.1458781632; .CNBlogsCookie=39EB7C846FF5A6CA5D762D210B954E55CE77A24D11C5203F6055DCAC93DFFF8EA7E405568F2D8CC9F00AFE43A859E71DE55AE6E79A030F7E74C231CECF7DA2DD88B734EA2ECA22DFED8C2ECAB85717B45434AABFE1202DA8266C7440562114D99D9C6767'
}
 
login_data = {'input1': '你的用户名加密后内容',
              'input2': '你的密码加密后内容',
              'remember': 'false'
              }
 
url = 'http://passport.cnblogs.com/user/signin'
req = s.post(url, data = login_data, headers=headers)
print(req.status_code)           #200
print(req.content.decode())      #{"success":false,"message":"您已处于登录状态"}
 
f = s.get('http://home.cnblogs.com/u/whatbeg/followers/1', headers=headers)
print(f.status_code)
print(f.text)

相关文章

  • 爬虫中的模拟登录

    使用Fiddler 抓取网络数据,登录'https://www.v2ex.com/',抓到一堆包,使用find功能...

  • 模拟登录之果壳网

    模拟登录 模拟登录常用于大型数据爬取,通过模拟登录,获得网站发给用户有效的 cookies,在爬虫爬取数据时,可以...

  • Python爬虫集合,20个爬虫项目让你一次吃到撑!!!

    Python爬虫入门实战教程目录(持续更新中......) 1、淘宝模拟登录 2、淘宝登录数据爬取 3、12306...

  • 爬虫模拟登录

    模拟登录心得:完全模拟浏览器的行为,得到链接,发送请求。 遇到的问题 1.get请求的链接可能与post请求的链接...

  • Scrapy爬虫模拟登录github

    scrapy爬虫框架模拟登录github 携带cookies / 以及在响应中自动查找action跳转的内容和网址...

  • 特斯拉API接口 - 授权登录

    搞了一天,就是拿不下,本来想越过官网跳转浏览器形式登录,直接抓接口模拟登录,发现不行,传统的爬虫是没办法模拟登录了...

  • 各类链接

    爬虫 使用python-aiohttp爬取今日头条 【Python】爬虫爬取各大网站新闻 Scrapy 模拟登录新...

  • 模拟登陆存在问题

    学习Python爬虫(七)--Scrapy模拟登录的post模拟登陆后,自己写了模拟登陆知乎首页的代码。 测试后发现无效

  • python爬虫系列-使用selenium模拟豆瓣登录

    title: python爬虫系列-使用selenium模拟豆瓣登录date: 2019-05-14 13:42:...

  • 003--Python爬虫自动登录

    1.解决爬虫采集相关网站数据时模拟自动登录 功能说明此处所说的模拟登录不是指利用网站本身提供的认证API接口进行登...

网友评论

      本文标题:爬虫中的模拟登录

      本文链接:https://www.haomeiwen.com/subject/cxmkqxtx.html