python 文本混淆绕过 获取图片文字

python 文本混淆绕过 获取图片文字

import io
import requests
from urllib.parse import urljoin
from parsel import Selector
try:
 from PIL import Image
except ImportError:
 import Image
import pytesseract
url = 'http://xxxx/hello.png'
resp = requests.get(url)
sel = Selector(resp.text)
# 从响应正文中提取图片名称
image_name = sel.css('.pn::attr("src")').extract_first()
# 拼接图片名和URL
image_url = urljoin(url, image_name)
# 请求图片,拿到图片的字节流内容
image_body = requests.get(image_url).content
# 使用Image.open打开图片字节流,得到图片对象
image_stream = Image.open(io.BytesIO(image_body))
print(image_stream)
# 使用光学字符识别从图片对象中读取文字并打印输出结果
# code =pytesseract.image_to_string(image_stream,lang="eng")
code =pytesseract.image_to_string(image_stream,lang="chi_sim")
print(code)


#coding:gbk
# import pytesseract  
# from PIL import Image
 
 
# # 使用pytesseract对英文进行识别,lang参数可省略
# code = pytesseract.image_to_string(Image.open(r'code.png'),lang="eng")
# print(code)
# # 使用pytesseract对中文(含英文,但识别率降低)进行识别
# code = pytesseract.image_to_string(Image.open(r'code.jpg'),lang='chi_sim')
# print(code)
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值