/ / Python Web Scrape (Anfragen, BeautifulSoup) - Python, Beautifulsoup, Python-Anfragen

Python Web Scrape (Anfragen, BeautifulSoup) - Python, BeautifulSoup, Python-Anfragen

Ich versuche, ein einfaches Web-Scrape-Skript zu schreiben, also habe ich diesen Code geschrieben und einen Fehler erhalten.

import requests
from bs4 import BeautifulSoup

r = requests.get("http://the website that I need.com")

soup = BeautifulSoup(r.content)

print(soup.prettify())

Und ich bekomme eine Fehlermeldung:

Traceback (most recent call last):
File "course.py", line 18, in <module>
print(soup.prettify())
File "C:Python34libencodingscp437.py", line 19, in encode
return codecs.charmap_encode(input,self.errors,encoding_map)[0]
UnicodeEncodeError: "charmap" codec can"t encode character "u203a" in position
32558: character maps to <undefined>

Ich benutze Python 3.4.0

Kann also jemand sagen, was los ist?

Antworten:

-1 für die Antwort № 1

Ich glaube, dass dies ein Encode-Problem ist: Versuchen Sie, einen Codierungstyp bei der Rückgabezeichenfolge hinzuzufügen:

Beispiel für die Kodierung nach utf-8 Suppe = BeautifulSoup (r.content.encode ("uft-8"))