S
S
Sergey Ilyin2020-11-21 19:08:35
Python
Sergey Ilyin, 2020-11-21 19:08:35

How to read doc file from a link?

Good afternoon. Task: read the doc-file from the link.

import requests as req
from io import BytesIO
# иногда сайт ругается на ssl, поэтому пусть этот кусочек тоже тут будет для нормальной работы
import ssl
ssl._create_default_https_context = ssl._create_unverified_context

# тело скрипта
url ='https://www.uralprombank.ru/files/misc/admiralgorshkov-15.doc'
file = req.get(url, verify=False).content
file = BytesIO(file).read()
file = file.decode('cp65001', 'ignore')
print(file)


the output is "empty rectangles". Apparently, the problem is in the encoding.
What am I doing wrong and how to fix it? Thanks in advance.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
PavelMos, 2020-11-21
@PavelMos

You output the contents of the dock to the console.

import urllib.request
url ='https://www.uralprombank.ru/files/misc/admiralgorshkov-15.doc'
urllib.request.urlretrieve(url, "с:\\text.doc")

https://docs.python.org/3.0/library/urllib.request.html

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question