Print Python beautiful soap text only

Asked 1 years ago, Updated 1 years ago, 395 views

import requests
from bs4 import BeautifulSoup

url = "https://toss.im/"

res = requests.get(url)

res.raise_for_status

soup = BeautifulSoup(res.text, "lxml")

toss = soup.find("li", attrs={"class":"p-navbar__item"})
print(toss.find_next_siblings("li"))

Do you know how to print out only text from this code?

print(toss.find_next_siblings("li").get_text()) but it doesn't work.

python beautifulsoup

2023-02-05 22:55

1 Answers

I don't know why you convert the html page to lxml.

import requests
from bs4 import BeautifulSoup

url = "https://toss.im/"

res = requests.get(url)
soup = BeautifulSoup(res.text, "html.parser")
print(soup.select_one('li'))


2023-02-05 22:56

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.