python - Crawl URL file to get final destination URL after redirects? -
python - Crawl URL file to get final destination URL after redirects? -
i have text file follows
http://url.com/r/gfdgdfg http://url.com/r/a32512f http://url.com/r/awdre25 http://url.com/r/agbfd35 http://url.com/r/nfg4622
is there way utilize python (trying simple script on linux box) crawl each url (load it) , final url? each url/link redirect , want url after redirects.
import requests urls = '''http://url.com/r/gfdgdfg http://url.com/r/a32512f http://url.com/r/awdre25 http://url.com/r/agbfd35 http://url.com/r/nfg4622''' x in urls.splitlines(): r = requests.get(x) print x, '=>', r.url
result:
http://url.com/r/gfdgdfg => http://lyrics.url.com http://url.com/r/a32512f => http://lyrics.url.com http://url.com/r/awdre25 => http://lyrics.url.com http://url.com/r/agbfd35 => http://lyrics.url.com http://url.com/r/nfg4622 => http://lyrics.url.com
python
Comments
Post a Comment