Return to Snippet

Revision: 7582
at July 30, 2008 13:41 by huacnlee


Initial Code
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

Initial URL
http://huacn.blogbus.com/logs/26387436.html

Initial Description
Python make url address to Tinyurl in article content like Twitter message

Initial Title
Python make url address to Tinyurl

Initial Tags
python, twitter

Initial Language
Python