cpeters5
asked on
Python - Internet access
I am adapting the following code from https://docs.python.org/3/tutorial/ section 10.7 Internet access:
from urllib.request import urlopen:
for line in urlopen('http://apps.rhs.org.uk/horticulturaldatabase/orchidregister/orchiddetails.asp?ID=171586'):
for line in urlopen('http://plantilus.com/plantdb/RlczLepr/index.html'):
line = line.decode('utf-8')
if 'Genus' in line or 'Seed' in line:
print(line)
Got expected results without any error.
When I changed to a different URL http://apps.rhs.org.uk/horticulturaldatabase/orchidregister/orchiddetails.asp?ID=171586
I got the UnicideDecodeError (invalid start byte)
Note: Similar code runs successfully in Perl. I hope to be able to do this in Python.
Hope someone here could explain what the problem is.
pax
from urllib.request import urlopen:
for line in urlopen('http://apps.rhs.org.uk/horticulturaldatabase/orchidregister/orchiddetails.asp?ID=171586'):
for line in urlopen('http://plantilus.com/plantdb/RlczLepr/index.html'):
line = line.decode('utf-8')
if 'Genus' in line or 'Seed' in line:
print(line)
Got expected results without any error.
When I changed to a different URL http://apps.rhs.org.uk/horticulturaldatabase/orchidregister/orchiddetails.asp?ID=171586
I got the UnicideDecodeError (invalid start byte)
Note: Similar code runs successfully in Perl. I hope to be able to do this in Python.
Hope someone here could explain what the problem is.
pax
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
pax