python识别二维码

1.安装库:

pip install Pillow
pip install pyzbar

2.完整代码:

import re
from pyzbar.pyzbar import decode
from PIL import Image
import requests_html

session = requests_html.HTMLSession()
images_url = '二维码图片地址'
images_file = session.get(images_url)
with open('xxx.png', 'wb') as f:
    f.write(images_file.content)
f.close()
image = 'xxx.png'
img = Image.open(image)
barcodes = decode(img)
url= ''
for barcode in barcodes:
    url = barcode.data.decode("utf-8")
print(url)




你可能感兴趣的:(爬虫,爬虫)