Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

BeautifulSoup and prettify() function

To parse html codes of a website, I decided to use BeautifulSoup class and prettify() method. I wrote the code below.

import requests
import bs4

response = requests.get("https://www.doviz.com")
soup = bs4.BeautifulSoup(response.content, "html.parser")
print(soup.prettify())

When I execute this code on Mac terminal, indentation of the codes are not set. On the other hand, If I execute this code on windows cmd or PyCharm, all codes are set.

Do you know the reason for this ?

like image 575
Goktug Avatar asked May 17 '26 18:05

Goktug


1 Answers

try this code:

import requests
from bs4 import BeautifulSoup
response = requests.get("https://www.doviz.com")
soup = BeautifulSoup(response.text, "html.parser")
print(soup.prettify())
like image 190
sushants367 Avatar answered May 20 '26 15:05

sushants367



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!