import io
from PIL import Image
from urllib.request import *
from urllib.parse import *
import pandas as pd
import numpy as np
import xlrd
import sys
import json
import pyzbar.pyzbar as pyzbar

import sys

if len(sys.argv) != 2:

print("统一社会信用代码注册号作为参数")
sys.exit(0) #输入统一社会信用代码

print("正在查询", sys.argv[1])
payload = {"regNo": sys.argv[1]}
payload = urlencode(payload).encode()
data = urlopen("http", data=payload).read().decode()

pos = data.find('pdf.action')
if pos == -1:

print("未查询到相关信息")
sys.exit(0)

uid = data[pos + 14:data.find('&', pos)]

img = urlopen("http".format(uid)).read()
img = Image.open(io.BytesIO(img))
img = img.convert("RGB")
qr = img.crop((910, 260, 1000, 345))
qr = qr.resize((x * 5 for x in qr.size))
qr = qr.save("test_bak.png", quality=95)

import pyzbar.pyzbar as pyzbar
import cv2
frame= cv2.imread("test_bak.png")
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
barcodes = pyzbar.decode(gray)
thre = 35
while (len(barcodes) == 0 and thre < 200):

ret, thresh = cv2.threshold(gray, thre, 255, cv2.THRESH_BINARY)
barcodes = pyzbar.decode(thresh)
thre = thre + 10

for barcode in barcodes:

(x, y, w, h) = barcode.rect
res=barcode.data

print(barcodes)

res = barcodes[0].data.decode()#转化字符
pos = res.find("id")#取地址ID
uid = res[pos + 3:res.find('&', pos)]#取地址&前面

res = urlopen(

"http".format(uid)).read().decode() #打开链接

import json

data = json.loads(res)
print("n企业名称:", data["ENTNAME"], "n统一社会信用代码:", data["UNISCID"],"n注册号:", data["REGNO"], "n法定代表人:",

  data["LEREP"], "\n手机号码1:", data["PHONE"], "\n手机号码2:", data["TEL"], "\n地址:", data["DOM"], "\n经营范围:",
  data["OPSCOPE"], ) #查询工商信息

标签: none

添加新评论