[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 23:11:15 CEST 2010
So I finally find a relevant example in the docs:
<http://docs.python.org/py3k/library/urllib.request.html?highlight=urllib#examples>
The first example gave me some understanding and led me to revising my code to
import urllib.request
f = urllib.request.urlopen('http://www.marketwatch.com/investing/currency/CUR_USDYEN')
a = f.read(20500).decode('utf-8')
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)
which works like a charm.
Dick
More information about the Tutor
mailing list