[英]How to get rid of BeautifulSoup error in Python
I am wondering how to fix this error I am trying to get stuff from the website我想知道如何解决这个错误 我想从网站上获取东西
t pyttsx3
import speech_recognition as sr
import speech_recognition
from bs4 import BeautifulSoup
r = sr.Recognizer()
def speak_text(command):
engine = pyttsx3.init()
engine.say(command)
engine.runAndWait()
source2: speech_recognition.Microphone
with sr.Microphone() as source2:
r.adjust_for_ambient_noise(source2, duration=0.2)
print("Listening...")
audio2 = r.listen(source2)
assert isinstance(audio2, object)
my_text = r.recognize_google(audio2)
print("Recognizing...")
if my_text == "test":
print("SECRET")
else:
soup = BeautifulSoup("google.com")
for link in soup.find_all("a"):
print(link.get("href"))
This is the error I get...这是我得到的错误...
GuessedAtParserWarning: No parser was explicitly specified, so I'm using the best available HTML parser for this system (" HTML. parser").
GuessedAtParserWarning:没有明确指定解析器,所以我使用了这个系统最好的可用 HTML 解析器(“HTML.parser”)。 This usually isn't a problem, but if you run this code on another 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 31 of the file PycharmProjects/pythonProject1/main.py.
导致此警告的代码位于文件 PycharmProjects/pythonProject1/main.py 的第 31 行。 To get rid of this warning, pass the additional argument 'features=" HTML. parser"' to the BeautifulSoup constructor
要消除此警告,请将附加参数 'features=" HTML.parser"' 传递给 BeautifulSoup 构造函数
thanks.谢谢。
Error message says it all.错误信息说明了一切。 Replace
代替
soup = BeautifulSoup("google.com")
with和
soup = BeautifulSoup("google.com", features="html.parserr")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.