测试网站:http://www.porters.vip/captcha/clicks.html
import cv2
import base64
import numpy as np
import nest_asyncio
nest_asyncio.apply()
from requests_html import AsyncHTMLSession
asession = AsyncHTMLSession()
def remove_bg(img):
cv2.imshow("img.pmg",img)
async def get_pyclock():
res = await asession.get('http://www.porters.vip/captcha/clicks.html')
script = """
() => {
return document.getElementById('clickCanvas').toDataURL("image/png")
}
"""
base64str = await res.html.arender(script=script)
img_base64 = base64.b64decode(base64str.split(",")[1])
with open('1.png','wb') as f:
f.write(img_base64) # 保存图像
img_np = np.frombuffer(img_base64, np.uint8)
img = cv2.imdecode(img_np, cv2.IMREAD_COLOR)
remove_bg(img)
return res
res = asession.run(get_pyclock)
cv2.waitKey(0)
cv2.destroyAllWindows()