import requests
from bs4 import BeautifulSoup url = "https://www.forbes.com/billionaires/" response = requests.get(url) soup = BeautifulSoup(response.content, "html.parser") # Find the container with the list of billionaires billionaires_container = soup.find("div", class_="personList") # Find all the names of the billionaires billionaires_names = billionaires_container.find_all("div", class_="personName") # Retrieve the names of the first 20 billionaires richest_people = [] for i in range(20): richest_people.append(billionaires_names[i].text.strip()) # Print the names of the 20 richest people for person in richest_people: print(person)
Comments
Post a Comment