not working. I am using python 3.3.2. please and thank you.

import urllib

u = urllib.request('http://www.ctabustracker.com/bustime/map/getBusesForRoute.jsp?route=22')
info = u.read()
f = open('rt22.xml', 'wb')
f.write(info)
f.close()

Recommended Answers

All 4 Replies

Not working --> Exception thrown. Solve the issue described by the exception traceback !

Look here.

Change your code to this ...

from urllib.request import urlopen

u = urlopen('http://www.ctabustracker.com/bustime/map/getBusesForRoute.jsp?route=22')
info = u.read()

print(type(info))  # just a test --> <class 'bytes'>

f = open('rt22.xml', 'wb')
f.write(info)
f.close()

# convert info to string before printing
print(info.decode())  # test

Notice that info is not a string object.

thank you so much. i am new to this. can you explain lines 6 and 13 please. would I need to input this?

Looks like lines 6 and 13 are just test prints for your information.
Most programmers just comment them out.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.