0

I'm learning how to parse HTML using Beautiful Soup. I've been working with NetBeans as IDE in a virtual environment (Python 3.6) and I had no problems.

My surprised was when trying a very simple code in order to find all the 'a' elements from a web site I got an error. If I tried to select all 'h3' or any other element it works but not when I try with 'a'.

import requests
import bs4
url = 'https://www.python.org/events/'
req = requests.get(url)
req.raise_for_status()
reqText = req.text
soup = bs4.BeautifulSoup(reqText, "html.parser")
selection1 = soup.find_all('a')
print(selection1)

The error says:

Traceback (most recent call last):
  File "C:\PROJECTS\Python36\src\new_main.py", line 9, in <module>
    print(selection)
  File "C:\Anaconda2\envs\env1a\lib\encodings\cp1252.py", line 19, in encode
    return codecs.charmap_encode(input,self.errors,encoding_table)[0]
UnicodeEncodeError: 'charmap' codec can't encode character '\u25bc' in position 211: character maps to <undefined>

I have another IDE installed (Spyder) and it worked when using it.

It looks like it's a problem with codecs. Could anybody tell me how can I fix this problem. Why Netbeans fails when selecting a very specific element and it works otherwise.

tdelaney
  • 73,364
  • 6
  • 83
  • 116
dangimar
  • 21
  • 2
  • Please verify that you're actually running in Python 3 by looking at the output of https://stackoverflow.com/questions/1093322/how-do-i-check-what-version-of-python-is-running-my-script#1093331 – supersam654 May 27 '18 at 22:23
  • Verified! It's Python 3.6.5 – dangimar May 28 '18 at 18:54

0 Answers0