I want to get both of names "Justin Cutroni" and "Krista Seiden" without the tags
this is my html code that I want to get the names by python3:
I used beautifulsoup
but I don't know how to get deep in the html codes and get the names.
import requests
from bs4 import BeautifulSoup as bs
web_pages = ["https://maktabkhooneh.org/learn/"]
def find_lessons(web_page):
# Load the webpage content
r = requests.get(web_page)
# Convert to a beautiful soup object
soup = bs(r.content, features="html.parser")
table = soup.select('div[]')
data = [x.text.split(';')[-1].strip() for x in table]
return data
find_teachers(web_pages[0])
CodePudding user response:
You are looking at course-card__title
, when it appears you want is course-card__teacher
. When you're using requests
, it's often more useful to look at the real HTML (using wget
or curl
) rather than the object model, as in your image.
What you have pretty much works with that change:
import requests
from bs4 import BeautifulSoup as bs
web_pages = ["https://maktabkhooneh.org/learn/"]
def find_teachers(web_page):
# Load the webpage content
r = requests.get(web_page)
soup = bs(r.content, features="html.parser")
table = soup.select('div[]')
return [x.text.strip() for x in table]
print(find_teachers(web_pages[0]))