Python urllib module: iterating over URL -


i'm trying fetch last 5 characteres page's html text , use them replace last 5 characteres in url, , try again. need repeat number of times.

this i've come with. @ moment, prints same url 5 times in row.

import urllib.request  prevurl = "http://www.pythonchallenge.com/pc/def/linkedlist.php?nothing=12345" in range(1,5):     urllib.request.urlopen(prevurl) url:         s = url.read()         prevurl.replace('[-5:]', 's[-5:]')     print(prevurl) 

i don't understand why negativations. use constructive criticism instead. great way encourage learning.

anyways, think figured out. takes steps, works way wanted.

import urllib.request  prevurl = "http://www.pythonchallenge.com/pc/def/linkedlist.php?nothing=12345" in range(1,400):     urllib.request.urlopen(prevurl) url:         s = url.read().decode("utf-8")         n1 = []         u1 = []         in s:             if i.isdigit():                 n1.append(i)                 n2 = ''.join(n1)         in prevurl:             if i.isdigit():                 u1.append(i)                 u2 = ''.join(u1)         if len(n2) != len(u2):             prevurl = prevurl.replace(prevurl[-(len(u2)):], n2)         else:             prevurl = prevurl.replace(prevurl[-(len(n2)):],n2)      print(prevurl) 

Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -