-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebscrapping table 3 espn exemplo duas tabela.py
43 lines (38 loc) · 1.43 KB
/
webscrapping table 3 espn exemplo duas tabela.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import requests
from bs4 import BeautifulSoup
from pathlib import Path
import pandas as pd
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
url = 'https://www.espn.com/nba/stats/player/_/season/2017/seasontype/2/table/offensive/sort/avgPoints/dir/desc'
driver = webdriver.Firefox()
driver.implicitly_wait(10)
driver.get(url)
#response = requests.get(url)
soup = BeautifulSoup(driver.page_source, "html.parser")
stat_table = soup.find_all('table', class_ = 'Table Table--align-right Table--fixed Table--fixed-left') #nome e rank de jogador
stat_table2 = soup.find_all('table', class_ = 'Table Table--align-right') #dados estatisticos
stat_table = stat_table[0]
stat_table2 = stat_table2[0]
rank = []
def pandas1():
for i, row in enumerate(stat_table.find_all('tr')):
rank.append([])
if i == 0:
for header in row.find_all('th'):
rank[i].append(header.text)
else:
for cell in row.find_all('td'):
rank[i].append(cell.text)
for i, row in enumerate(stat_table2.find_all('tr')):
if i == 0:
for header in row.find_all('th'):
rank[i].append(header.text)
else:
for cell in row.find_all('td'):
rank[i].append(cell.text)
return rank
rank = pandas1()
df = pd.DataFrame(rank[1:], columns=(tuple(rank[0])))
df.to_excel("natalia_linda4.xlsx",index=False)
print('acabou')