Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find the redirected URL with Python requests library or otherwise [duplicate]

This URL:

http://www.yellowpages.com.sg/newiyp/UrlRedirect?applicationInd=yp&searchType=68&searchCriteria=multiple+choices&accessType=8&advertiserName=Multiple+Choices&url=62CE8F02A1BE04A51C81F85D1CE8B54DFC608A9CDA925C15EED5DA6DD90E3F7DC99CFF77216D1D1083877BA841EB97C3

Redirects to:

http://www.callmyname.sg/view/Multiple+Choices/Uk9JRC9TRzA0SkstQkJDNkRFNTEuMTNCNS9FRDY5LUE4NzgtRUY=

When using requests, I get:

import requests

url = "http://www.yellowpages.com.sg/newiyp/UrlRedirect?applicationInd=yp&searchType=68&searchCriteria=multiple+choices&accessType=8&advertiserName=Multiple+Choices&url=62CE8F02A1BE04A51C81F85D1CE8B54DFC608A9CDA925C15EED5DA6DD90E3F7DC99CFF77216D1D1083877BA841EB97C3"
response = requests.get(url)
response.url

It returns the same first URL, not the redirected URL.

like image 680
muffinz Avatar asked Dec 25 '22 23:12

muffinz


1 Answers

Here is a sample. I used "bit.ly", because I got 403 using your URL.


>>> url = "http://bit.ly/18SuUzJ"
>>> r = requests.get(url, allow_redirects=False)
>>> r.status_code
    301
>>> r.headers['Location']
    'http://stackoverflow.com/'

like image 145
Deck Avatar answered Dec 28 '22 06:12

Deck