from bs4 import BeautifulSoup
import requests
import csv
r = requests.get(
"https://www.berufsstart.de/unternehmen/bundesland/baden-wuerttemberg-top-100.php")
soup = BeautifulSoup(r.text, 'html.parser')
numbers = []
names = []
cities = []
for num in soup.findAll("div", class_="col-sm-2"):
num = num.get_text(strip=True, separator=",")
if num:
numbers.append(num.split(',')[1])
for name in soup.findAll("strong", class_="h2"):
names.append(name.text)
for city in soup.findAll("div", class_="col-sm-5 infobereich"):
cities.append(city.get_text(strip=True, separator=" ").split(" ")[1])
with open("kas.csv", 'w', newline="") as f:
writer = csv.writer(f)
writer.writerow(["Name", "City", "Number"])
for a, b, c in zip(names, cities, numbers):
writer.writerow([a, b, c])
print("Done")
Вывод: просмотр в режиме онлайн