python - function decoding twitter short url: what if there are several urls? -


i coding function decode twitter short urls in twitter stream have captured:

def decode_short_url(x):     urls = re.findall('http[s]?://(?:[a-za-z]|[0-9]|[$-_@.&+]|[!*\(\),]|(?:%[0-9a-fa-f][0-9a-fa-f]))+', x)     short_url in urls:         try:             res = urllib.request.urlopen(short_url)             actual_url = res.geturl()             return(actual_url)         except:             return(short_url) 

but when apply tweets contain several links :

tweets['urls'] = tweets['text'].apply(decode_short_url) 

i don't urls in new variable tweets.urls, first one. idea on how of them?

thanks!

when return something, that's end of function. instead of returning each url, add them list , return list after loop

:)


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -