【发布时间】:2011-11-01 10:59:57
【问题描述】:
我已经看过这个帖子了 - How can I unshorten a URL?
我对已解决答案的问题(即使用 unshort.me API)是我专注于缩短 youtube 链接。由于 unshort.me 很容易使用,因此几乎 90% 的结果都带有我无法解决的验证码。
到目前为止,我一直坚持使用:
def unshorten_url(url):
resolvedURL = urllib2.urlopen(url)
print resolvedURL.url
#t = Test()
#c = pycurl.Curl()
#c.setopt(c.URL, 'http://api.unshort.me/?r=%s&t=xml' % (url))
#c.setopt(c.WRITEFUNCTION, t.body_callback)
#c.perform()
#c.close()
#dom = xml.dom.minidom.parseString(t.contents)
#resolvedURL = dom.getElementsByTagName("resolvedURL")[0].firstChild.nodeValue
return resolvedURL.url
注意:cmets 中的所有内容都是我在使用返回验证码链接的 unshort.me 服务时尝试做的。
有没有人知道在不使用 open 的情况下完成此操作的更有效方法(因为它浪费带宽)?
【问题讨论】:
-
您在使用什么网址缩短器时遇到问题?你为什么要使用 unshort.me 呢?您的代码应该已经可以工作了,它应该按照重定向到真实 url 来缩短 url。
-
我不明白您所说的“不使用 open”是什么意思。短链接是进入别人数据库的钥匙;不查询数据库就无法展开链接。
-
当我阅读我引用的帖子 (stackoverflow.com/questions/4201062/…) 时,它看起来像命令 urlopen GET 请求整个页面,所以当我要寻找的只是链接时,这是一种带宽浪费。建议的方法对我不起作用(unshort.me),所以我决定看看是否还有其他选择。
标签: python curl youtube hyperlink urllib