Open the first N characters of a url file with Python

I am trying to clear data from large files .txton the Internet using Python 3.

The data that I receive is reliably located in the first 2000 characters of the text, and the download / download time makes downloading the entire file quite expensive.

Is there a way to load only the first N characters or lines from a remote file?

Something like the following:

import urllib.request
with open(urllib.request.urlopen(myurl)) as myfile:
        head= [next(myfile) for x in range(10)]
print(head)
0
source share

Source: https://habr.com/ru/post/1540178/


All Articles