数据采集从入门到放弃 第二章:HTTP协议介绍

第二章主要是讲了些HTTP协议相关,属于基础知识,关于这块,有一本书比较收到好评,叫做《图解HTTP》,公众号后台回复“http”可以观看。

目录:

  1. HTTP协议

    1. HTTP的特性

    2. HTTP报文

    3. 会话跟踪

    4. 跨站攻击

    5. 实践

  2. TCP协议

    1. TCP 的特性

    2. 三次握手与四次挥手

    3. SYN攻击

    4. TCP KeepAlive

  3. 实战:模拟登陆

    1. 场景

    2. 手动

    3. 自动

    4. 实践

本章会留下较多实践,难度对初学者来说很大。有兴趣去尝试吗,有知乎的session_token参数,还有美团的登录的参数解决。

美团的有几个重点参数需要解决:

  1. password

  2. fingerprint

  3. csrf

  4. _token

关于参数“_token”提示:

> window.location.origin + r
<< "https://passport.meituan.com/account/unitivelogin?risk_partner=0&uuid=1dff88e4c8294f67b2b6.1551710089.1.0.0&service=www&continue=https%3A%2F%2Fwww.meituan.com%2Faccount%2Fsettoken%3Fcontinue%3Dhttp%253A%252F%252Fbj.meituan.com%252F"

所以难点就在于函数Rohr_Opt.reload,大家可以自己去多尝试。

附上github模拟登陆的代码

#!/usr/bin/env python
# -*- coding: utf-8 -*-
import re
import requests

headers = {
    'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8',
    'Accept-Encoding': 'gzip, deflate, br',
    'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8',
    'Connection': 'keep-alive',
    'Host': 'github.com',
    'Upgrade-Insecure-Requests': '1',
    'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36'
}
s = requests.session()
s.headers.update(headers)


def get_token():
    url = 'https://github.com/login'
    response = s.get(url, timeout=10)
    pat = 'name=\"authenticity_token\" value=\"(.*?)\"'
    return re.findall(pat, response.text)[0]


def login(authenticity_token, account, password):
    payload = {
        'commit': 'Sign in',
        'utf8': '\u2713',
        'authenticity_token': authenticity_token,
        'login': account,
        'password': password,
    }
    url = 'https://github.com/session'
    response = s.post(url, data=payload)
    print(response.text)
    # do whatever you want


if __name__ == '__main__':
    account, password = '', ''
    authenticity_token = get_token()
    login(authenticity_token, account, password)

更多内容可以阅读原文

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值