Search code examples
pythonpython-3.xurllib

Read URL in URLLIB starting from a different starting character


I open a URL through python and print the characters, but the first approximately 1000 characters are useless and i dont want them to appear. How to I start the print from a number to another predefined number?

I have tried to look up solutions but nothing says anything about starting from a different pre defined number.

from urllib.request import urlopen

link = "https://www.abc.net.au/" 

#dummy URL. Its on the internet, but dont want to use the real one for privacy

f = urlopen(link)
print(f.readline(1000:2000))


Solution

  • You can simply index the string returned:

    from urllib.request import urlopen
    
    link = "https://www.abc.net.au/"
    
    f = urlopen(link)
    print(f.read()[1000:2000])