如何读取保存的谷歌搜索结果页面?

2024-04-26 06:12:19 发布

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

我在谷歌搜索了一些文本,并用html保存了页面

然而,当我打开它时,内容消失了

这是我保存的html的link

如何恢复内容

with open('sample.html', 'r') as f:
    text = f.read()

'万象城上海首秀' in text # False, but it should be True

多谢各位


Tags: sampletextin文本false内容readhtml
1条回答
网友
1楼 · 发布于 2024-04-26 06:12:19

您可能需要为此使用^{}。以下是如何做到这一点:

>>> from bs4 import BeautifulSoup as bs
>>> soup = bs(open("file.html","r").read(), "html.parser")
>>> '万象城上海首秀' in soup.text
True
>>> 

相关问题 更多 >