# -*-coding:utf8-*-
# !/usr/bin/env python
import requests, json
import base64
class PdfOcr(object):
def __init__(self):
self.url = 'xxxx'
def ocr_pdf(self, filepath):
with open(filepath, "rb") as imageFile:
image_str = base64.b64encode(imageFile.read())
bodytmp = {
"image_base64": image_str,
# "template_name": name
}
headers = {
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.102 Safari/537.36'
}
res = requests.post(self.url, data=bodytmp, headers=headers, timeout=30)
html = res.content.decode('utf8')
main_content = json.loads(html)
rest = main_content['result']
result = ''
if rest is None:
return None
for i in rest:
result += i['words']
return result
if __name__ == '__main__':
F = PdfOcr()
fp = '20170507104235.pdf'
# name = "fhx_zg_template"
output = F.ocr_pdf(fp)
print(output)
网页post 上传文件请求
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
推荐阅读更多精彩内容
- 首先我们在使用的时候需要根据接口返回的数据进行封装javabean对象,便于后面使用。 构建RetrofitSer...
- get请求 HTML界面 默认就是get方式提交表单数据 提交的数据, 必须有name属性 PHP界面 如何接收g...
- 本文示例是在 httpclient4.3.6 下进行的测试。#### 发送Get请求: 发送Post请求,同表单P...
- 在调用第三方api接口时,有时会遇到通过http协议上传图片,以下是一个微信公众平台新增永久素材的例子(使用前请阅...