1

I have a url like https://guangdiu.com/go.php?id=5347317. When you open this in the browser, it will redirect 2 times. I am trying to get the last direct url.

I am trying to follow this url to get the last direct url: https://stackoverflow.com/questions/20475552/python-requests-library-redirect-new-url/20475639

I tried them all, none of them worked. I am always getting the same url.

What's wrong?

yong ho
  • 3,576
  • 9
  • 34
  • 67
  • 1
    Redirection is done via js. I'm afraid you'll have to use `selenium`. – t.m.adam May 05 '18 at 16:40
  • @t.m.adam How do you find out it's done via js? Maybe I can find the specific js file, and figure it out. – yong ho May 06 '18 at 04:25
  • If you print the response `.text` you'll see a script tag that redirects to a new url via `window.location`. If you follow the second url, it pulls some js from a third url via `location.replace`. If you follow the third url there is some script that sets cookies and redirects to the final url. – t.m.adam May 06 '18 at 07:29
  • Below is the third url with the js that does the final redirection, in case you want to study it: https://union-click.jd.com/jdc?e=&p=AyIHZRprFQYXAlMbWCVGTV8LRGtMR1dGFxBFC1pXUwkEAEAdQFkJBVsRBxcBVRhETEdOWmVpXhFDcF4UaDhSZGR7IW4dQEAUWStNVxlsEQZVEkcUBg4GUQpYFwkTBF4eXyUCEw9SHV8QBhQGZRtaFAMTAl0ZUx0yEABUEloVChU3VRprXmwTN1QrWxEBFgNXGF8SBhYDVitcJVJHWw1ENRYDEgBlK2slMiIHZRg%3D&t=W1dCFFlQCxxKQgFHRE5XDVULR0UVBhcCUxtYCltXWwg%3D I assume that the query string is dynamic, but the script seems to be static. – t.m.adam May 06 '18 at 07:33

0 Answers0