obligatory warning that I am just learning python.
My question is why do I receive the error below after being prompted for a file name?[Errno 22] invalid mode ('r') or filename: 'text.txt'
My code: (it works but the html won't load)
import urllib
from BeautifulSoup import *
url = raw_input('Enter - ')
html = urllib.urlopen(url).read()
soup = BeautifulSoup(html)
tags = soup('a')
for tag in tags:
print tag.get('href', None)
IOError: [Errno 22] invalid mode ('r') or filename: ''
Thank you for your help,
Edit: Traceback
Traceback (most recent call last):
File "C:UsersabrowDesktopPythonbrowser.py", line 6, in <module>
html = urllib.urlopen(url).read()
File "C:Python27liburllib.py", line 87, in urlopen
return opener.open(url)
File "C:Python27liburllib.py", line 208, in open
return getattr(self, name)(url)
File "C:Python27liburllib.py", line 292, in open_http
import httplib
File "C:Python27libhttplib.py", line 79, in <module>
import mimetools
File "C:Python27libmimetools.py", line 6, in <module>
import tempfile
File "C:Python27libtempfile.py", line 35, in <module>
from random import Random as _Random
File "C:UsersabrowDesktopPythonrandom.py", line 2, in <module>
handle = open(name, 'r')
IOError: [Errno 2] No such file or directory: 'text.txt'
Aucun commentaire:
Enregistrer un commentaire