PyDictionary/beauthoulsoup的问题

2024-05-19 06:23:50 发布

您现在位置:Python中文网/ 问答频道 /正文

我在macossierra上运行python3,需要创建由特定单词的同义词组成的句子。为此,我使用PyDictionary。在

但是,当运行我的代码(如下所示)时,我会得到一个错误(Python解释器)和一个警告(beauthoulsoup)。在

输出:

/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/beautifulsoup4-4.5.3-py3.5.egg/bs4/__init__.py:181: UserWarning: No parser was e
xplicitly specified, so I'm using the best available HTML parser for this system ("html.parser"). This usually isn't a problem, but if you run this code on an
other system, or in a different virtual environment, it may use a different parser and behave differently.

The code that caused this warning is on line 53 of the file main.py. To get rid of this warning, change code that looks like this:

 BeautifulSoup([your markup])

to this:

 BeautifulSoup([your markup], "html.parser")

  markup_type=markup_type))
Traceback (most recent call last):
  File "main.py", line 53, in <module>
    edison()
  File "main.py", line 29, in edison
    say(respond(["I", "am", "happy", "to", "hear", "that", "html.parser"]) + "!")
  File "/path/to/code/respond.py", line 9, in respond
    output = (output + " " + (random.choice(dictionary.synonym(word, "html.parser"))))
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/random.py", line 265, in choice
    return seq[i]
KeyError: 0

主.py:

^{pr2}$

回复.py:

import random
from PyDictionary import PyDictionary
dictionary = PyDictionary()

def respond(wordList):
    output = ""
    for word in wordList:
        output = (output + " " + (random.choice(dictionary.synonym(word, "html.parser"))))
    return output

Tags: inpyparseroutputthatmainhtmlline
1条回答
网友
1楼 · 发布于 2024-05-19 06:23:50

我也发现了你同样的问题,但在https://github.com/VitaliyRodnenko/geeknote/issues/305处就解决了

也许你可以试试看,我相信你会找到答案的。我不能直接帮你,因为我不做PyDictionary,但我希望你能找到答案。 我希望有帮助。在

相关问题 更多 >

    热门问题