4

(Title might change not too sure what to call it)

So I'm trying to open a URL that directs to a random page (This URL: http://anidb.net/perl-bin/animedb.pl?show=anime&do.random=1) and I want to return where that URL goes

    randomURL = urllib.urlopen("http://anidb.net/perl-bin/animedb.pl?show=anime&do.random=1")
    print(randomURL)  

That's what I (stupidly) thought would work. I imported urllib

2
  • Yes I am using Python3 Commented Nov 12, 2013 at 0:58
  • So you want to detect what URL a different URL gets redirected to? Is that right? Commented Nov 12, 2013 at 1:11

1 Answer 1

1

In Python 3 >, urllib.urlopen was replaced by urllib.request.urlopen. Change the request line to this:

urllib.request.urlopen('http://anidb.net/perl-bin/animedb.pl?show=anime&do.random=1')

For more, you can see the docs

But if you want to have the url, which is a bit more difficult, you can take a look at urllib.request.HTTPRedirectHandler

Sign up to request clarification or add additional context in comments.

1 Comment

The questioner wants to get the final URL (ie the URL that is redirected to).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.