python - Python BeautifulSoup 'Slice' 对象没有属性 'lower'
问题描述
我有这个脚本可以运行以从收件箱的电子邮件中提取数据,但是它在几天前可以工作,但是现在当我运行它时,每当有电子邮件进入“切片对象没有属性较低”时,它都会给我一个错误并说错误发生soup = BeautifulSoup(msg, "html.parser")
在线路上。这是什么意思,我该如何解决?这是代码:
import email
import imaplib
from bs4 import BeautifulSoup
import time
import sys
username = 'xx.xxx@xxx.ca'
password = 'xx'
mail = imaplib.IMAP4_SSL('imap-mail.outlook.com')
(retcode, capabilities) = mail.login(username, password)
mail.select('inbox')
n=0
while True:
(retcode, messages) = mail.search(None, 'UNSEEN', '(SUBJECT "xxxx- ")', '(FROM "xx.xx@xxxx.ca")')
if retcode == 'OK':
for num in messages[0].split():
n=n+1
print('Processing Email ' + str(n))
typ, data = mail.fetch(num, '(RFC822)')
for response_part in data:
if isinstance(response_part, tuple):
original = email.message_from_bytes(response_part[1])
print("Subject: " + original['Subject'])
body = data[0][1]
msg = email.message_from_bytes(body)
content = msg.get_payload(decode=True)
soup = BeautifulSoup(msg, "html.parser")
text = soup.get_text()
fontdef, email1 = text.split('-->')
email2, signature = email1.split('________________________________________________')
print(email2)
typ, data = mail.store(num,'+FLAGS','\\Seen')
time.sleep(10)
解决方案
推荐阅读
- sql - 在透视 xml 后将 xmltype 解析为表
- flutter - 找不到提供程序 - Flutter
- power-automate - 使用 MS Flow 在 Microsoft Teams 上未呈现自适应卡片图像
- apache-spark - 为什么使用 Summarizer 的流式查询失败并显示“要求失败:没有向此汇总器添加任何内容”?
- flask - 无法在 PyCharm 中安装 Flask
- flutter - 当我保持活动小部件颤动时如何再次请求数据?
- angular - 赋值表达式的左侧必须是变量或属性访问
- keras - 填充形状在 Keras 中是如何工作的?
- php - Laravel - 如何获取输入并将其从一个视图传递到另一个视图 (Mpdf)
- azure - .net core web api 在发布到 azure 时响应 500