0

I'm new to python.
I'm trying to write the html I get with requests and BeautifulSoup to a file so I can read it better,
but I just get this error:

File "C:\python\manga\manga.py", line 12, in <module>
    html.write(results)
TypeError: write() argument must be str, not Tag

Here is the code I'm running:

import requests
from bs4 import BeautifulSoup

URL = 'https://mangapark.net/manga/tensei-shitara-slime-datta-ken-fuse'
page = requests.get(URL)
soup = BeautifulSoup(page.content, 'html.parser')

results = soup.find('section', class_='manga')

with open('html.txt', 'w') as html:
    html.write(results)

# print(results.prettify())

Printing it gives me what I want.

2 Answers2

0

In soup, find function returns as Tag, For printing it firstly you should convert it to String. So you should try this:

results = soup.find('section', class_='manga').text
0

This should work:

with open('html.txt', 'w', encoding='utf-8') as html:
    html.write(str(results))
papayanuts
  • 16
  • 1