python - 内存错误使用漂亮的汤用python解析~100mb html文件
问题描述
运行以下代码时出现内存错误:
from bs4 import BeautifulSoup
with open(r'C:\user\table.html', 'r') as f:
soup = BeautifulSoup(f, 'html.parser')
found = soup.find("td", text = "A")
print(found)
f.closed
此代码适用于小型 html 文件。但是,当我使用 ~100mb html 表运行它时,它会慢慢消耗内存,直到程序崩溃。任务管理器显示 python.exe 在程序崩溃时占用 2gb 内存。我试过浏览 beautifulsoup 文档,但我无法弄清楚为什么这个程序占用的内存比我的 html 文件的大小多 20 倍。
解决方案
推荐阅读
- javascript - 用于 UI 的 Phaser 3 动态场景选择
- arrays - 如何在 Solidity 中创建动态内存数组?
- c# - 脚手架控制器在 Ubuntu 20.04 的 asp.net core 5 中不起作用
- javascript - 有没有更有效的方法来获取 Javascript 中对象中的多个最小值?
- mongodb - 带有 dart 包 mongo_dart 的 Atlas mongoDB 云服务导致连接异常
- python - 使用 python 混淆文本文件 - 通过反转单词并在它们之间插入特定数量的随机字符
- android - 访问嵌套片段嵌入为
- ansible - 如何使用 Ansible 在 ESXI 中创建虚拟机?
- php - 如何使用 cmd 创建最新 8.0 版本的 laravel 项目?
- php - 用户购买产品时,如何在 ACF 字段中自动添加文本?(PHP/WordPress)