Hi All,
I am following the phyton course and i got to the " 12 - urllinks - Python for Everybody Course" video.
I tried to installed and placed the folder he suggested into where i´m running the python from and it doesn´t work.
the teachers code is:
# To run this, download the BeautifulSoup zip file
# http://www.py4e.com/code3/bs4.zip
# and unzip it in the same directory as this file
import urllib.request, urllib.parse, urllib.error
from bs4 import BeautifulSoup
import ssl
# Ignore SSL certificate errors
ctx = ssl.create_default_context()
ctx.check_hostname = False
ctx.verify_mode = ssl.CERT_NONE
url = input('Enter - ')
html = urllib.request.urlopen(url, context=ctx).read()
soup = BeautifulSoup(html, 'html.parser')
# Retrieve all of the anchor tags
tags = soup('a')
for tag in tags:
print(tag.get('href', None))
and when i run it i get the following error:
Enter - http://www.dr-chuck.com/
Traceback (most recent call last):
File "/Users/luis/Desktop/Py/code3/urllinks.py", line 16, in <module>
soup = BeautifulSoup(html, 'html.parser')
File "/Users/luis/Desktop/Py/code3/bs4/__init__.py", line 215, in __init__
self._feed()
File "/Users/luis/Desktop/Py/code3/bs4/__init__.py", line 239, in _feed
self.builder.feed(self.markup)
File "/Users/luis/Desktop/Py/code3/bs4/builder/_htmlparser.py", line 164, in feed
parser.feed(markup)
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/html/parser.py", line 110, in feed
self.goahead(0)
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/html/parser.py", line 170, in goahead
k = self.parse_starttag(i)
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/html/parser.py", line 344, in parse_starttag
self.handle_starttag(tag, attrs)
File "/Users/luis/Desktop/Py/code3/bs4/builder/_htmlparser.py", line 62, in handle_starttag
self.soup.handle_starttag(name, None, None, attr_dict)
File "/Users/luis/Desktop/Py/code3/bs4/__init__.py", line 404, in handle_starttag
self.currentTag, self._most_recent_element)
File "/Users/luis/Desktop/Py/code3/bs4/element.py", line 1001, in __getattr__
return self.find(tag)
File "/Users/luis/Desktop/Py/code3/bs4/element.py", line 1238, in find
l = self.find_all(name, attrs, recursive, text, 1, **kwargs)
File "/Users/luis/Desktop/Py/code3/bs4/element.py", line 1259, in find_all
return self._find_all(name, attrs, text, limit, generator, **kwargs)
File "/Users/luis/Desktop/Py/code3/bs4/element.py", line 516, in _find_all
strainer = SoupStrainer(name, attrs, text, **kwargs)
File "/Users/luis/Desktop/Py/code3/bs4/element.py", line 1560, in __init__
self.text = self._normalize_search_value(text)
File "/Users/luis/Desktop/Py/code3/bs4/element.py", line 1565, in _normalize_search_value
if (isinstance(value, str) or isinstance(value, collections.Callable) or hasattr(value, 'match')
AttributeError: module 'collections' has no attribute 'Callable'
I tried already:
to install beautifulsoup using the sudo pip
to download the zip file, unzipped and placed in the same folder
do anyone had the same issue?
Thanks a lot guys!!
Note: im using macOS