(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

有帮助吗?

解决方案

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

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top