gpt4 book ai didi

python - BeautifulSoup find_all UnicodeEncodeError

转载 作者:太空宇宙 更新时间:2023-11-04 03:22:18 25 4
gpt4 key购买 nike

<分区>

我从 tutorial 中获得了以下代码:

from bs4 import BeautifulSoup
import requests
req=requests.get("http://www.aflcio.org/Legislation-and-Politics/Legislative-Alerts")
data=req.text
soup=BeautifulSoup(data)
letters=soup.find_all("div",class_="ec_statements")
print(letters)

我收到以下错误:

Traceback (most recent call last):
File ".\scr3.py", line 7, in <module>
print(letters)
File "C:\Users\adi\AppData\Local\Programs\Python\Python35\lib\encodings\cp437.py", line 19, in encode
return codecs.charmap_encode(input,self.errors,encoding_map)[0]
UnicodeEncodeError: 'charmap' codec can't encode character '\u2019' in position 7787: character maps to <undefined>

如果我尝试将 encode('utf-8') 方法应用于 letters 对象,我会收到一个属性错误消息“ResultSet object has no attribute encode ".

有人知道打印字母对象的解决方法吗?我在 Windows 7 上使用 Python 3.5 和 BeautifulSoup 4。

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com