# -*-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協議上傳圖片,以下是一個微信公眾平臺新增永久素材的例子(使用前請閱...