fix: 修复登录二维码扫描不上的bug

This commit is contained in:
Relakkes 2023-06-13 14:00:04 +08:00
parent e82dcae02f
commit c0a783fa35
2 changed files with 11 additions and 7 deletions

View File

@ -4,7 +4,7 @@
# 仓库描述
这个代码仓库是一个利用[playwright](https://playwright.dev/)的爬虫程序
可以准确地爬取小红书、抖音的笔记、评论等信息,大概原理是利用playwright登录成功后保留登录成功后的上下文浏览器环境通过上下文浏览器环境执行JS表达式获取一些加密参数再使用python的httpx发起异步请求相当于使用Playwright搭桥免去了复现核心加密JS代码逆向难度大大降低。
可以准确地爬取小红书、抖音的笔记、评论等信息原理是利用playwright登录成功后保留登录成功后的上下文浏览器环境通过上下文浏览器环境执行JS表达式获取一些加密参数再使用python的httpx发起异步请求相当于使用Playwright搭桥免去了复现核心加密JS代码逆向难度大大降低。
## 主要功能

View File

@ -1,12 +1,9 @@
import json
import time
import base64
import random
import hashlib
import base64
from io import BytesIO
from typing import Optional, Dict, List, Tuple
from PIL import Image
from PIL import Image, ImageDraw
from playwright.async_api import Cookie
from playwright.async_api import Page
@ -30,7 +27,14 @@ def show_qrcode(qr_code: str):
qr_code = qr_code.split(",")[1]
qr_code = base64.b64decode(qr_code)
image = Image.open(BytesIO(qr_code))
image.show()
# Add a square border around the QR code and display it within the border to improve scanning accuracy.
width, height = image.size
new_image = Image.new('RGB', (width + 20, height + 20), color=(255, 255, 255))
new_image.paste(image, (10, 10))
draw = ImageDraw.Draw(new_image)
draw.rectangle((0, 0, width + 19, height + 19), outline=(0, 0, 0), width=1)
new_image.show()
def get_user_agent() -> str: