[Tutor] A question on getting binary data from the net
Gregor Lingl
glingl@aon.at
Fri, 12 Jul 2002 01:09:36 +0200
>
> import urllib
> def randombytes(n=128):
> urlstr="http://www.fourmilab.ch/cgi-bin/uncgi/Hotbits?nbytes="+str(n)
> t = urllib.urlopen(urlstr).read()
> start = t.find('<pre>')+5
> end = t.find('</pre>')
> hexes = ''.join(t[start:end].split())
> bytes=[]
> for i in range(0,len(hexes),2):
> bytes.append(int(hexes[i:i+2], 16))
> return bytes
>
I think, of course, this could be done in two or three lines if
one knew how to fetch binary data from the net - using this form
of the url:
http://www.fourmilab.ch/cgi-bin/uncgi/Hotbits?nbytes=128&fmt=bin
Can somebody explain how to accomplish this in Python?
Gregor