Thank you very much!

(I'm step closer to final version of recipe.)
I did come to next two "challenges". But let's take it step by step.
In recipe I use this code:
Code:
def print_version(self, url):
split_url = url.split("/")
print 'URL1= ', split_url[1]
print 'URL2= ', split_url[2]
print 'URL3= ', split_url[3]
print 'URL4= ', split_url[4]
print 'URL5= ', split_url[5]
print 'URL6= ', split_url[6]
print_url = 'http://www.rtvslo.si/index.php?c_mod=news&op=print&id=' + split_url[6]
print 'THIS URL WILL PRINT: ',print_url
return print_url
With this I found that
ID of the article (
six digit number) – needed for print version – is not always on same "place". Usually it’s under syntax
split_url[6], but sometimes it’s at
split_url[5].
So, the links to articles are like either this:
- http://something1/something2/something3/something4/something5/###### (ID is sixth segment)
- http://something1/something2/something3/something4/###### (ID is fifth segment)
I looked through forum, but couldn’t find similar problem or solution. I understand logic, but don’t know the syntax for it, so please help me:
if split_url[6] is empty (meaning that link has only 5 segments. Or - another idea - maybe somehow to check if split_url[6] is number?)
print_url = ‘http://…id=’ + split_url[5] (create link to print version of article with 5th segment)
or else
print_url = ‘http://…id=’ + split_url[6] (create link to print version of article with 6th segment)
return print_url
I hope this is possible, I just don't know how.