I want to extract only text in list format from tag list extracted by BeautifulSoup

Asked 1 years ago, Updated 1 years ago, 99 views

 from bs4 import BeautifulSoup

r=requests.get("***************")

soup = BeautifulSoup(r.content, "html.parser")

class=soup.find_all("div", class_="word")

At this rate, scraping will remain in the list surrounded by html tags.

I don't need tags, so I'd like to keep them in a list format with the tags removed.

python web-scraping beautifulsoup

2022-09-30 14:02

1 Answers

If you only need text, you can do the following.

 from bs4 import BeautifulSoup
import requests

r=requests.get("***************")

soup = BeautifulSoup(r.content, "html.parser")

wordclass=soup.find_all("div", class_="word")

wordlist = [x.text for x in wordclass ]

print(wordlist)


2022-09-30 14:02

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.