Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 urlopen error
#1
Hi, Python Web Scrapers,

I wrote a simple code to use urlopen function, but it didn't work.
I don't know what's wrong with my code.

Python 3.8.2
OS: Windows
IDE: VS Code

Here's my code

import urllib.request
url='http://python.org/'
get=urllib.request.urlopen(url)
print(get)
you can see the error picture in :
https://imgur.com/ifOMZHO
İmage
Quote
#2
Pro tip: You can input traceback errors into error tags (just click the red cross in the reply text box) so users can see the error without clicking external links and immediately identify the most important part of the post.

I believe the only thing you're missing is to write 'get.read()' rather than just the 'get' in the print function.

So it should be
import urllib.request
url='http://python.org/'
get=urllib.request.urlopen(url)
print(get.read())
Hope that helps!
Quote
#3
FYI: requests is so much more elegant code same as yours looks similar,
but there's a lot more to offer, see: https://requests.readthedocs.io/en/master/

needs to be installed once, pip install requests (request with an s = requests)

simple example:
import requests
url='http://python.org/'
response = requests.get(https://qrznow.com/real-time-band-conditions/)
print(response.content)
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  urllib.request.urlopen and proxy perseus142 0 65 May-29-2020, 08:46 AM
Last Post: perseus142

Forum Jump:


Users browsing this thread: 1 Guest(s)