Reputation: 33
OK, here's basically what I am trying to do:
The URL http://anidb.net/perl-bin/animedb.pl?show=animelist&adb.search="Cowboy Bebop"&do.search=search redirects to http://anidb.net/perl-bin/animedb.pl?show=anime&aid=23
Let's say I want to write down the ID (23, in that example) in a XML file.
Upvotes: 1
Views: 155
Reputation: 3520
Unrelated to the actual coding question. But you might want to use the AniDB search data instead of querying their website.
Upvotes: 0
Reputation: 9451
Result of urlopen
has method geturl
which provides the redirect information. Then you can parse it using regular expression.
import urllib2
import re
url = 'http://anidb.net/perl-bin/animedb.pl?show=animelist&adb.search=%22Cowboy%20Bebop%22&do.search=search'
headers = {"User-agent": "Mozilla/5.0"}
request = urllib2.Request(url, None, headers)
result = urllib2.urlopen(request)
r = re.search("aid=(\d+)", result.geturl())
print r.group(1)
Upvotes: 1
Reputation: 5374
Do this:
var uri = window.location.href
var params = uri.split("?")[1].split("&");
args = {};
for(var i=0; i<params.length; i++) {
p = params[i].split("=");
args[p[0]] = p[1];
}
alert(args['aid']);
[EDIT: Saw python tag]
So, in python, if you have a URL, you could split it very similarly:
uri = "http://anidb.net/perl-bin/animedb.pl?show=anime&aid=23"
params = uri.split('?')[1].split('&')
args={}
for kv in params:
p = kv.split('=')
args[p[0]] = p[1]
But again, I have no idea where python comes into play in your question, as it seems the scripts getting hit are perl.
Upvotes: 0