在学习过程中,又了解到了几种针对爬虫的限制机制。

页面加载设置cookie

字符串拼接cookie有后端生成动态脚本,查找cookie字段名字找不到,但是可以找document.cookie呀

参数base64

base64是一种很有特征的编码,就算看不出,常用的编码那几种挨个试一下,哪个返回正确就是哪个

http2

requests不支持http2,建议使用httpx

1
2
with httpx.Client(http2=True) as client:
pass

tls指纹特征

服务器使用tls的cipher suits等字段生成独特的客户端ID。
使用Wireshark等抓包工具查找TLS layer中ServerHello消息,ssl.handshake.type == 2
如果你使用httpx,可以使用如下方式设置httpx的ssl_context

1
2
3
4
5
6
import httpx
ssl_context = httpx.create_ssl_context()
ssl_context.set_ciphers('ECDHE-RSA-AES128-GCM-SHA256')

with httpx.Client(http2=True, verify=ssl_context) as client:
pass