我正在使用此代码在 python 3 中取消缩短网址,但代码按原样返回网址(已缩短),那么我该怎么做才能使其取消缩短?
import requests
import http.client
import urllib.parse as urlparse
def unshortenurl(url):
parsed = urlparse.urlparse(url)
h = http.client.HTTPConnection(parsed.netloc)
h.request('HEAD', parsed.path)
response = h.getresponse()
if response.status/100 == 3 and response.getheader('Location'):
return response.getheader('Location')
else: return url
千巷猫影
相关分类