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)