[Tutor] Need help with converting script using 2.6's urllib2 to Python 3.1
Richard D. Moores
rdmoores at gmail.com
Mon Oct 25 14:46:27 CEST 2010
The lines below are the essence of a 2.6 script that gets the current
USD/yen quote.
I'd like to convert the script to 3.1, but I can't understand the docs
for the 3.1 urllib module. Please someone tell me what to do.
(Converting 'print rate' to 'print(rate)' I understand.)
import urllib2
a = urllib2.urlopen('http://www.marketwatch.com/investing/currency/CUR_USDYEN').read(20500)
b = a[19000:20500]
idx_pricewrap = b.find('pricewrap')
context = b[idx_pricewrap:idx_pricewrap+80]
idx_bgLast = context.find('bgLast')
rate = context[idx_bgLast+8:idx_bgLast+15]
print rate
Thanks,
Dick Moores
More information about the Tutor
mailing list