BeautifulSoup and prettify() function
17,661
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())
Author by
Goktug
Updated on June 04, 2022Comments
-
Goktug almost 2 years
To parse html codes of a website, I decided to use
BeautifulSoup
class andprettify()
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 ?
-
Mew over 2 yearsOr, in words: construct the soup using
response.text
, notresponse.content
.