我正在尝试从https://2018.masters.com/en_US/scores/stats/fir.html抓取一张桌子 检查网站本身时,可以在源代码中找到表代码。但是,当我使用Beautiful Soup打印它或使用带有Selenium的chrome驱动程序打开它时,我似乎找不到相同的表或任何表。
答案 0 :(得分:0)
您可以通过json响应访问数据。一旦有了它,就可以将json结构放平到一个数据框中。
import pandas as pd
from pandas.io.json import json_normalize
import requests
url = 'https://2018.masters.com/en_US/xml/gen/scores/fir.json'
response = requests.get(url).json()
table = response['round1']['player']
df = json_normalize(table)
df = df.stats.apply(pd.Series)[0].apply(pd.Series).merge(df, left_index = True, right_index = True).drop(["stats"], axis = 1)
输出:
print (df.to_string())
round1 round2 round3 round4 total id name
0 13 / 14 = 92.86% 10 / 14 = 71.43% 7 / 14 = 50.00% 10 / 14 = 71.43% 40 / 56 = 71.43% 32839 Hideki Matsuyama
1 13 / 14 = 92.86% 12 / 14 = 85.71% 11 / 14 = 78.57% 12 / 14 = 85.71% 48 / 56 = 85.71% 1666 Bernhard Langer
2 12 / 14 = 85.71% 10 / 14 = 71.43% 11 / 14 = 78.57% 8 / 14 = 57.14% 41 / 56 = 73.21% 34360 Patrick Reed
3 12 / 14 = 85.71% 6 / 14 = 42.86% 18 / 28 = 64.29% 32366 Kevin Chappell
4 12 / 14 = 85.71% 8 / 14 = 57.14% 12 / 14 = 85.71% 10 / 14 = 71.43% 42 / 56 = 75.00% 29478 Kevin Kisner
5 12 / 14 = 85.71% 10 / 14 = 71.43% 14 / 14 = 100.00% 10 / 14 = 71.43% 46 / 56 = 82.14% 40098 Matthew Fitzpatrick
6 12 / 14 = 85.71% 10 / 14 = 71.43% 22 / 28 = 78.57% 1823 Larry Mize
7 12 / 14 = 85.71% 10 / 14 = 71.43% 22 / 28 = 78.57% 39113 Shubhankar Sharma
8 12 / 14 = 85.71% 7 / 14 = 50.00% 8 / 14 = 57.14% 8 / 14 = 57.14% 35 / 56 = 62.50% 28237 Rory McIlroy
9 11 / 14 = 78.57% 5 / 14 = 35.71% 7 / 14 = 50.00% 8 / 14 = 57.14% 31 / 56 = 55.36% 29725 Tony Finau
10 11 / 14 = 78.57% 12 / 14 = 85.71% 12 / 14 = 85.71% 12 / 14 = 85.71% 47 / 56 = 83.93% 25804 Bubba Watson
11 11 / 14 = 78.57% 8 / 14 = 57.14% 8 / 14 = 57.14% 13 / 14 = 92.86% 40 / 56 = 71.43% 23108 Matt Kuchar
12 11 / 14 = 78.57% 10 / 14 = 71.43% 21 / 28 = 75.00% 21209 Sergio Garcia
13 11 / 14 = 78.57% 9 / 14 = 64.29% 20 / 28 = 71.43% 27556 Ted Potter, Jr.
14 11 / 14 = 78.57% 8 / 14 = 57.14% 19 / 28 = 67.86% 1887 Mark O'Meara
15 11 / 14 = 78.57% 8 / 14 = 57.14% 19 / 28 = 67.86% 20848 Angel Cabrera
16 11 / 14 = 78.57% 10 / 14 = 71.43% 11 / 14 = 78.57% 11 / 14 = 78.57% 43 / 56 = 76.79% 24138 Ian Poulter
17 11 / 14 = 78.57% 9 / 14 = 64.29% 8 / 14 = 57.14% 11 / 14 = 78.57% 39 / 56 = 69.64% 27644 Brian Harman
18 11 / 14 = 78.57% 7 / 14 = 50.00% 9 / 14 = 64.29% 11 / 14 = 78.57% 38 / 56 = 67.86% 34046 Jordan Spieth
19 11 / 14 = 78.57% 12 / 14 = 85.71% 10 / 14 = 71.43% 10 / 14 = 71.43% 43 / 56 = 76.79% 34098 Russell Henley
20 11 / 14 = 78.57% 10 / 14 = 71.43% 9 / 14 = 64.29% 13 / 14 = 92.86% 43 / 56 = 76.79% 26476 Chez Reavie
21 10 / 14 = 71.43% 12 / 14 = 85.71% 13 / 14 = 92.86% 12 / 14 = 85.71% 47 / 56 = 83.93% 26596 Ryan Moore
22 10 / 14 = 71.43% 9 / 14 = 64.29% 7 / 14 = 50.00% 8 / 14 = 57.14% 34 / 56 = 60.71% 48081 Xander Schauffele
23 10 / 14 = 71.43% 8 / 14 = 57.14% 18 / 28 = 64.29% 45486 Joaquin Niemann (A)
24 10 / 14 = 71.43% 11 / 14 = 78.57% 11 / 14 = 78.57% 11 / 14 = 78.57% 43 / 56 = 76.79% 47959 Bryson DeChambeau
25 10 / 14 = 71.43% 11 / 14 = 78.57% 10 / 14 = 71.43% 12 / 14 = 85.71% 43 / 56 = 76.79% 40026 Daniel Berger
26 10 / 14 = 71.43% 9 / 14 = 64.29% 11 / 14 = 78.57% 13 / 14 = 92.86% 43 / 56 = 76.79% 21528 Henrik Stenson
27 10 / 14 = 71.43% 9 / 14 = 64.29% 19 / 28 = 67.86% 23821 Yusaku Miyazato
28 10 / 14 = 71.43% 10 / 14 = 71.43% 10 / 14 = 71.43% 9 / 14 = 64.29% 39 / 56 = 69.64% 24502 Adam Scott
29 10 / 14 = 71.43% 10 / 14 = 71.43% 9 / 14 = 64.29% 11 / 14 = 78.57% 40 / 56 = 71.43% 32102 Rickie Fowler
30 10 / 14 = 71.43% 9 / 14 = 64.29% 8 / 14 = 57.14% 11 / 14 = 78.57% 38 / 56 = 67.86% 30110 Kyle Stanley
31 10 / 14 = 71.43% 6 / 14 = 42.86% 16 / 28 = 57.14% 25686 Jason Dufner
32 10 / 14 = 71.43% 9 / 14 = 64.29% 11 / 14 = 78.57% 10 / 14 = 71.43% 40 / 56 = 71.43% 32816 Satoshi Kodaira
33 10 / 14 = 71.43% 8 / 14 = 57.14% 18 / 28 = 64.29% 46837 Yuxin Lin (A)
34 10 / 14 = 71.43% 5 / 14 = 35.71% 10 / 14 = 71.43% 10 / 14 = 71.43% 35 / 56 = 62.50% 24024 Zach Johnson
35 10 / 14 = 71.43% 9 / 14 = 64.29% 9 / 14 = 64.29% 13 / 14 = 92.86% 41 / 56 = 73.21% 22405 Justin Rose
36 10 / 14 = 71.43% 9 / 14 = 64.29% 19 / 28 = 67.86% 53165 Doc Redman (A)
37 10 / 14 = 71.43% 6 / 14 = 42.86% 16 / 28 = 57.14% 33293 Thomas Pieters
38 10 / 14 = 71.43% 7 / 14 = 50.00% 17 / 28 = 60.71% 48084 Wesley Bryan
39 10 / 14 = 71.43% 5 / 14 = 35.71% 8 / 14 = 57.14% 12 / 14 = 85.71% 35 / 56 = 62.50% 34363 Tyrrell Hatton
40 10 / 14 = 71.43% 11 / 14 = 78.57% 21 / 28 = 75.00% 2300 Ian Woosnam
41 9 / 14 = 64.29% 8 / 14 = 57.14% 12 / 14 = 85.71% 10 / 14 = 71.43% 39 / 56 = 69.64% 12716 Charley Hoffman
42 9 / 14 = 64.29% 8 / 14 = 57.14% 8 / 14 = 57.14% 9 / 14 = 64.29% 34 / 56 = 60.71% 33448 Justin Thomas
43 9 / 14 = 64.29% 7 / 14 = 50.00% 11 / 14 = 78.57% 9 / 14 = 64.29% 36 / 56 = 64.29% 28089 Jason Day
44 9 / 14 = 64.29% 6 / 14 = 42.86% 15 / 28 = 53.57% 31323 Gary Woodland
45 9 / 14 = 64.29% 4 / 14 = 28.57% 6 / 14 = 42.86% 9 / 14 = 64.29% 28 / 56 = 50.00% 25364 Paul Casey
46 9 / 14 = 64.29% 9 / 14 = 64.29% 18 / 28 = 64.29% 54318 Matt Parziale (A)
47 9 / 14 = 64.29% 9 / 14 = 64.29% 10 / 14 = 71.43% 11 / 14 = 78.57% 39 / 56 = 69.64% 33399 Adam Hadwin
48 9 / 14 = 64.29% 4 / 14 = 28.57% 13 / 28 = 46.43% 46435 Austin Cook
49 9 / 14 = 64.29% 10 / 14 = 71.43% 11 / 14 = 78.57% 13 / 14 = 92.86% 43 / 56 = 76.79% 25198 Francesco Molinari
50 9 / 14 = 64.29% 6 / 14 = 42.86% 15 / 28 = 53.57% 27896 Ross Fisher
51 9 / 14 = 64.29% 6 / 14 = 42.86% 8 / 14 = 57.14% 10 / 14 = 71.43% 33 / 56 = 58.93% 29454 Bernd Wiesberger
52 9 / 14 = 64.29% 5 / 14 = 35.71% 12 / 14 = 85.71% 11 / 14 = 78.57% 37 / 56 = 66.07% 35296 Haotong Li
53 9 / 14 = 64.29% 10 / 14 = 71.43% 10 / 14 = 71.43% 11 / 14 = 78.57% 40 / 56 = 71.43% 1226 Fred Couples
54 9 / 14 = 64.29% 6 / 14 = 42.86% 15 / 28 = 53.57% 10423 Mike Weir
55 9 / 14 = 64.29% 9 / 14 = 64.29% 9 / 14 = 64.29% 12 / 14 = 85.71% 39 / 56 = 69.64% 26499 Rafael Cabrera Bello
56 9 / 14 = 64.29% 13 / 14 = 92.86% 6 / 14 = 42.86% 9 / 14 = 64.29% 37 / 56 = 66.07% 29221 Webb Simpson
57 8 / 14 = 57.14% 10 / 14 = 71.43% 10 / 14 = 71.43% 9 / 14 = 64.29% 37 / 56 = 66.07% 30925 Dustin Johnson
58 8 / 14 = 57.14% 10 / 14 = 71.43% 18 / 28 = 64.29% 35450 Patrick Cantlay
59 8 / 14 = 57.14% 7 / 14 = 50.00% 8 / 14 = 57.14% 7 / 14 = 50.00% 30 / 56 = 53.57% 26851 Marc Leishman
60 8 / 14 = 57.14% 10 / 14 = 71.43% 18 / 28 = 64.29% 29420 Billy Horschel
61 8 / 14 = 57.14% 12 / 14 = 85.71% 9 / 14 = 64.29% 12 / 14 = 85.71% 41 / 56 = 73.21% 46970 Jon Rahm
62 8 / 14 = 57.14% 10 / 14 = 71.43% 9 / 14 = 64.29% 10 / 14 = 71.43% 37 / 56 = 66.07% 52375 Doug Ghim (A)
63 8 / 14 = 57.14% 10 / 14 = 71.43% 8 / 14 = 57.14% 11 / 14 = 78.57% 37 / 56 = 66.07% 27408 Martin Kaymer
64 8 / 14 = 57.14% 7 / 14 = 50.00% 15 / 28 = 53.57% 1717 Sandy Lyle
65 8 / 14 = 57.14% 6 / 14 = 42.86% 14 / 28 = 50.00% 26331 Charl Schwartzel
66 8 / 14 = 57.14% 6 / 14 = 42.86% 14 / 28 = 50.00% 26908 Yuta Ikeda
67 8 / 14 = 57.14% 5 / 14 = 35.71% 6 / 14 = 42.86% 9 / 14 = 64.29% 28 / 56 = 50.00% 1810 Phil Mickelson
68 8 / 14 = 57.14% 4 / 14 = 28.57% 9 / 14 = 64.29% 12 / 14 = 85.71% 33 / 56 = 58.93% 25632 Jimmy Walker
69 8 / 14 = 57.14% 7 / 14 = 50.00% 4 / 14 = 28.57% 11 / 14 = 78.57% 30 / 56 = 53.57% 8793 Tiger Woods
70 7 / 14 = 50.00% 7 / 14 = 50.00% 9 / 14 = 64.29% 9 / 14 = 64.29% 32 / 56 = 57.14% 6567 Vijay Singh
71 7 / 14 = 50.00% 9 / 14 = 64.29% 9 / 14 = 64.29% 12 / 14 = 85.71% 37 / 56 = 66.07% 27064 Jhonattan Vegas
72 7 / 14 = 50.00% 6 / 14 = 42.86% 9 / 14 = 64.29% 13 / 14 = 92.86% 35 / 56 = 62.50% 37455 Si Woo Kim
73 7 / 14 = 50.00% 8 / 14 = 57.14% 15 / 28 = 53.57% 29970 Dylan Frittelli
74 7 / 14 = 50.00% 6 / 14 = 42.86% 13 / 28 = 46.43% 24361 Pat Perez
75 7 / 14 = 50.00% 7 / 14 = 50.00% 14 / 28 = 50.00% 32139 Danny Willett
76 7 / 14 = 50.00% 9 / 14 = 64.29% 12 / 14 = 85.71% 10 / 14 = 71.43% 38 / 56 = 67.86% 30911 Tommy Fleetwood
77 7 / 14 = 50.00% 8 / 14 = 57.14% 15 / 28 = 53.57% 32757 Patton Kizzire
78 6 / 14 = 42.86% 9 / 14 = 64.29% 15 / 28 = 53.57% 6373 Jose Maria Olazabal
79 6 / 14 = 42.86% 4 / 14 = 28.57% 10 / 28 = 35.71% 22378 Trevor Immelman
80 6 / 14 = 42.86% 8 / 14 = 57.14% 9 / 14 = 64.29% 10 / 14 = 71.43% 33 / 56 = 58.93% 29974 Branden Grace
81 6 / 14 = 42.86% 8 / 14 = 57.14% 14 / 28 = 50.00% 27349 Alex Noren
82 6 / 14 = 42.86% 7 / 14 = 50.00% 14 / 14 = 100.00% 8 / 14 = 57.14% 35 / 56 = 62.50% 26329 Louis Oosthuizen
83 6 / 14 = 42.86% 7 / 14 = 50.00% 7 / 14 = 50.00% 13 / 14 = 92.86% 33 / 56 = 58.93% 35891 Cameron Smith
84 6 / 14 = 42.86% 11 / 14 = 78.57% 8 / 14 = 57.14% 12 / 14 = 85.71% 37 / 56 = 66.07% 30978 Kiradech Aphibarnrat
85 5 / 14 = 35.71% 11 / 14 = 78.57% 16 / 28 = 57.14% 29518 Brendan Steele
86 3 / 14 = 21.43% 5 / 14 = 35.71% 8 / 28 = 28.57% 52569 Harry Ellis (A)