【发布时间】:2021-10-18 14:37:02
【问题描述】:
我在 blob 存储中有一个 docx 文件。
我尝试做的是获取 blob 中文件的链接/路径或 url 以应用此功能:
def get_docx_text(path):
"""
Take the path of a docx file as argument, return the text in unicode.
"""
document = zipfile.ZipFile(path)
xml_content = document.read('word/document.xml')
document.close()
tree = XML(xml_content)
paragraphs = []
for paragraph in tree.getiterator(PARA):
texts = [node.text
for node in paragraph.getiterator(TEXT)
if node.text]
if texts:
paragraphs.append(''.join(texts))
text = '\n\n'.join(paragraphs)
return (paragraphs,text)
在def get_docx_text(path)的参数路径中我想放文件的路径。
我该怎么做?
我尝试了类似的方法但不起作用:
from azure.storage.blob import BlobServiceClient, BlobClient, ContainerClient
connection_string='...'
blob_service_client = BlobServiceClient.from_connection_string(connection_string)
service_client = BlobServiceClient.from_connection_string(connection_string)
client = service_client.get_container_client("name_container")
bc = client.get_blob_client(blob="bronze/txt_name.docx")
with open("txt_name.docx", 'wb') as file:
data = bc.download_blob()
file.write(data.readall())
【问题讨论】:
-
您遇到了什么问题?
-
ResourceNotFoundError:指定的 blob 不存在。但我想这不是获取路径的好方法
-
方法正确。您能否检查一下您指定的名称 (
bronze/txt_name.docx) 是否确实存在于 blob 容器中? -
它是 sink/bronze/txt_name.docx 但我该怎么做才能将此文件的路径提供给 def get_docx_text(path) 函数?
-
请尝试
bc = client.get_blob_client(blob="sink/bronze/txt_name.docx")。