community,
I would like to deal with web scraping just for my own interest. The topic is very exciting and you can certainly gain a lot of interesting insights with the data available on the net.
In my first project I would like to generate some football data. For example, you can find information about previous injuries on Transfermarkt Leroy Sane.
Goal: To scrape the whole table.
Current status: I've managed to read out the Injuries column. Unfortunately I also get data from the "Missed matches" column.
Question: Is there a better way to get the exact values from each column? Or is there even a better way to scrape whole tables?
Code:
import requests
import csv
import re
from bs4 import BeautifulSoup
url = "https://www.transfermarkt.de/havard-nordtveit/verletzungen/spieler/192565"
heads = {'User-Agent' : 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.110 Safari/537.36'}
response = requests.get(url, headers=heads)
html_icerigi = response.text
soup = BeautifulSoup(html_icerigi, "html.parser")
injuries = soup.find_all(class_="hauptlink")
injuries_list = []
for injury in injuries:
injuries_list.append(injury.text)
print(injuries_list)
I am still at the beginning, you are the professionals. I am looking forward to learning.
Thanks, if you invest time to help me.