Python 独立代码不';我不能在Anki插件中工作

Python 独立代码不';我不能在Anki插件中工作,python,beautifulsoup,anki,Python,Beautifulsoup,Anki,下面的代码工作正常,但当我使用与Anki插件相同的代码时,BeautifulSoup会引发属性错误 以下是工作代码: from bs4 import BeautifulSoup s = '''<style>.card { font-family: arial; font-size: 20px; text-align: center; color: black; background-color: white; } </style>question &l

下面的代码工作正常,但当我使用与Anki插件相同的代码时,
BeautifulSoup
会引发属性错误

以下是工作代码:

from bs4 import BeautifulSoup

s = '''<style>.card {
 font-family: arial;
 font-size: 20px;
 text-align: center;
 color: black;
 background-color: white;
 }
 </style>question

 <hr id=answer>

 answer''' 

soup = BeautifulSoup(s, "html.parser")
soup.find("style").clear()
words = soup.text.strip().split()
print words

>>> [u'question', u'answer']

我想我使用的是
bs4
,因为我从aqt.editor import*导入
。以下是act.editor的内容:

我之所以执行此导入操作,只是因为我无法在加载项中从bs4 import BeautifulSoup导入
(另一个让我困惑的问题!)

我运行的是一个win7 virtualbox,除了Anki之外,它没有安装python,以确保我使用的是Anki安装附带的python环境


提前谢谢

你需要一份《美丽的汤4》。请在此处下载最新版本:


解压缩代码并将文件夹“bs4”复制到Anki Add-On文件夹。然后重新启动Anki。

它需要的对象不是字符串。我猜它需要一个
BeautifulSoup
实例。尝试添加行
raiseexception(repr(BeautifulSoup)+“+repr(type(BeautifulSoup))
并显示它打印的内容-我猜它与Anki外部的
BeautifulSoup
有所不同。
from aqt.reviewer import Reviewer
from aqt.editor import *

def newAnswerCard(self, ease):
    "Reschedule card and show next."
    if self.mw.state != "review":
        # showing resetRequired screen; ignore key
        return
    if self.state != "answer":
        return
    if self.mw.col.sched.answerButtons(self.card) < ease:
        return
    if ease == 1:
        s = '''<style>.card {
         font-family: arial;
         font-size: 20px;
         text-align: center;
         color: black;
         background-color: white;
        }
        </style>question

        <hr id=answer>

        answer''' 

        soup = BeautifulSoup(s, "html.parser")
        soup.find("style").clear()
        words = soup.text.strip().split()

    self.mw.col.sched.answerCard(self.card, ease)
    self._answeredIds.append(self.card.id)
    self.mw.autosave()
    self.nextCard()

origAnswerCard = Reviewer._answerCard
Reviewer._answerCard = newAnswerCard
Traceback (most recent call last):
  File "aqt\webview.py", line 21, in link
  File "aqt\reviewer.py", line 323, in _linkHandler
  File "C:\Users\A\AppData\Roaming\Anki2\addons\amintest2.py", line 27, in newAnswerCard
    soup = BeautifulSoup(s, "html.parser")
  File "thirdparty\BeautifulSoup.py", line 1521, in __init__
  File "thirdparty\BeautifulSoup.py", line 1146, in __init__
  File "thirdparty\BeautifulSoup.py", line 1188, in _feed
  File "sgmllib.py", line 104, in feed
  File "sgmllib.py", line 138, in goahead
  File "sgmllib.py", line 296, in parse_starttag
  File "sgmllib.py", line 338, in finish_starttag
  File "thirdparty\BeautifulSoup.py", line 1343, in unknown_starttag
AttributeError: 'str' object has no attribute 'text'