图片验证码解决方法

使用PIL标注图片库

# python图片标准库
from PIL import Image
import pytesseract

# 创建图片对象
image = Image.open("test3.jpg")

# 图片转为字符串
s = pytesseract.image_to_string(image)

print(s)

解决验证码问题基本思路与方法

# -*- coding: utf-8 -*-
"""
Created on Sat Dec  1 16:24:18 2018

@author: python
"""
from PIL import Image
import pyteeseract
from selenium import webdriver
from lxml import etree

#访问网站的到html

url = "https://www.douban.com/"
driver = webdriver.Chrome()
driver.get(url)
# 把验证码图片下载到本地
parseHtml = etree.HTML(driver.page_source)
r_List = parseHtml.xpath()
res = requests.get(r_List[0])
res.encoding="utf-8"
html = res.content
with open("验证码.png","wb") as f:
    f.write(html)
# 把图片 -->字符串
image = Image.open("验证码.png")
yzm = pytesseract.image_to_string(image)
# 发送到输入框

driver.find_element_by_xxx().send_keys(yzm))
    
    

# 把图片 -->字符串
发布了77 篇原创文章 · 获赞 3 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/qq_24137739/article/details/90609412