/ Published in: Python
Python make url address to Tinyurl in article content like Twitter message
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
def tiny_url(url): """å°†url转æ¢æˆtinyurl""" apiurl = "http://tinyurl.com/api-create.php?url=" tinyurl = urllib.urlopen(apiurl + url).read() return tinyurl def content_tiny_url(content): """让消æ¯é‡Œé¢çš„连接转æ¢æˆæ›´çŸçš„Tinyurl""" regex_url = r'http:\/\/([\w.]+\/?)\S*' for match in re.finditer(regex_url, content): url = match.group(0) content = content.replace(url,tiny_url(url)) return content
URL: http://huacn.blogbus.com/logs/26387436.html