Помощь вывод данных

OlegMoney

Новичок
Пользователь
Июл 24, 2022
6
0
1
Как вывести данные в два столбца эксель файла, 1-имя, 2-рейтинг ;)
На данный момент получается слитно.
Python:
from selenium import webdriver
driver = webdriver.Chrome()
import csv
import pandas as pd
 
driver.get('https://www.whoscored.com/Teams/30/Show/England-Tottenham') 
from selenium.webdriver.common.by import By
players_lines = driver.find_elements(By.XPATH,"//tbody[@id='player-table-statistics-body']/tr")
results = {}
for player in players_lines:
    name = player.find_element(By.XPATH, './/span').text
    rating = player.find_element(By.XPATH, ".//td[contains(@class,'rating')]").text
    results[rating] = [name]
 
 
df = pd.DataFrame.from_dict (results, orient='index'). reset_index()
print(df)
df.to_csv('England-Tottenham.csv')
Код:
 

4olshoy_blen

Активный пользователь
Пользователь
Ноя 13, 2022
137
32
28
Python:
from selenium import webdriver
from selenium.webdriver.common.by import By
import pandas as pd

driver = webdriver.Chrome()
driver.get('https://www.whoscored.com/Teams/30/Show/England-Tottenham')

players = driver.find_element(By.ID, 'player-table-statistics-body').find_elements(By.TAG_NAME, 'tr')
results = {}

for player in players:
    player_name = player.find_element(By.TAG_NAME, 'span').text
    rating = player.find_element(By.CLASS_NAME, 'rating').text
    results[player_name] = rating

df = pd.DataFrame.from_dict(results, orient='index').reset_index()
df.to_csv('England-Tottenham.csv')
 

Форум IT Специалистов