Michał
Michał

Reputation: 61

How can i handle memory error on html file?

I have this kind of code

URL = r"C:\Users\jarze\PycharmProjects\CSV-modifier\venv\html.html"
html_report_part1 = open(URL, 'r', encoding="UTF-8").read()
soup = BeautifulSoup(html_report_part1, "html.parser")

and its return this kind of error:

During handling of the above exception, another exception occurred: MemoryError

Upvotes: 0

Views: 342

Answers (1)

UWTD TV
UWTD TV

Reputation: 910

Try:

URL = r"C:\Users\jarze\PycharmProjects\CSV-modifier\venv\html.html"
html_report_part1 = open(URL, 'r', encoding="UTF-8")
html_text = ''
for line in html_report_part1.readlines():
    html_text += line
soup = BeautifulSoup(html_text, "html.parser")

Upvotes: 1

Related Questions