Oct-03-2016, 11:16 PM
Hi,
I'm working my way through an example in a book. However, it is return an unexpected value. Wonder if someone could help point out what/where I did wrong.
I tried to trace where it went wrong by only defining the function as:
I'm working my way through an example in a book. However, it is return an unexpected value. Wonder if someone could help point out what/where I did wrong.
baseUrl ="http://pythonscraping.com" source = "www.pythonscraping.com/sites/default/files/lrg_0.jpg" def getAbsoluteURL(baseUrl, source): if source.startswith("http://www."): url = "http://"+source[11:] elif source.startswith("http://"): url = source elif source.startswith("www."): url = source[4:] url = "http://"+source else: url = baseUrl+"/"+source if baseUrl not in url: return None return urlWhen I run the following code:
fileUrl = getAbsoluteURL(baseUrl, source) print(fileUrl)I got the value None. I thought that the second elif statement would evaluate to True, in which the url returned would be "http://pythonscraping.com/sites/default/files/lrg_0.jpg" as opposed to None.
I tried to trace where it went wrong by only defining the function as:
def getAbsoluteURL(baseUrl, source): if source.startswith("http://www."): url = "http://"+source[11:] elif source.startswith("http://"): url = source elif source.startswith("www."): url = source[4:] url = "http://"+sourceHowever, the return value still is None.