4

(标题可能会改变,不太清楚该叫什么)

所以我试图打开一个指向随机页面的 URL(这个 URL:http ://anidb.net/perl-bin/animedb.pl?show=anime&do.random= 1),我想返回那个网址去

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

这就是我(愚蠢地)认为会起作用的方法。我导入了 urllib

4

1 回答 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

于 2013-11-12T01:00:34.350 回答