Answer the question
In order to leave comments, you need to log in
How to check if a file is downloaded from a link?
The task is this.
There is a list of links.
When you click on some of them, the file starts to load.
But how can you filter out these links (that is, determine whether the file will be loaded or not)?
It is desirable to code in Python or a link where to read about it.
Answer the question
In order to leave comments, you need to log in
Among the HTTP response headers is Content-Type
, which takes the value of one of the MIME types . The value text/html
corresponds to the HTML page and the value application/octet-stream
corresponds to the file being uploaded.
import requests
if __name__ == "__main__":
r = requests.get('https://toster.ru/q/303883')
r.raise_for_status()
mime_type = r.headers['content-type']
if mime_type == 'application/octet-stream':
print('It is a binary file')
if mime_type.startswith('text/'):
print('It is a text')
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question