我正在尝试使用 bs4 打开 html 文件,但出现此错误

问题描述 投票:0回答:1

MarkupResemblesLocatorWarning:输入看起来更像是文件名而不是标记。您可能想要打开此文件并将文件句柄传递到 Beautiful Soup 中。 汤 = BeautifulSoup(html_doc,"lxml")

(很抱歉问题的格式不好,因为我还是初学者)

from bs4 import BeautifulSoup
html_doc="File_Path"
soup = BeautifulSoup(html_doc,"lxml")
bgs=soup.find_all('img')
print(bgs)
python-3.x parsing beautifulsoup html-parsing
1个回答
0
投票

我找到了答案,并认为将其留在这里给可能面临同样问题的人 先打开文件,然后再将其传递到 bs4

html_doc=open("filepath")

然后将其传递到汤对象内部

soup=BeautifulSoup(html_doc,"lxml")
© www.soinside.com 2019 - 2024. All rights reserved.