LoginSignup
0
1

Python 短縮URL展開

Posted at

メモ

import requests

res = requests.head(url)
if int(res.status_code / 100) != 3:
    return res.url
else:
    return res.headers['Location']

https://a.r10.to/hUR2Oe のようにステータスコードが 301 になる場合の対策
requests.get(url).url では無理な場合

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1