2017-01-19 2 views
0

Ich versuche, die Tabellendaten von der Website http://bet.hkjc.com/racing/index.aspx?date=22-01-2017&venue=ST&raceno=1&lang=en zu extrahieren Die Tabelle mit den Pferdedaten ist, was ich extrahieren möchte. Ich benutze dieses Bit Code, aber es gibt mir ein leeres Array zurückTabellendaten werden nicht mit Python extrahiert

page = requests.get("http://bet.hkjc.com/racing/index.aspx?date=22-01-2017&venue=ST&raceno=1&lang=en") 
tree = html.fromstring(page.content) 
temp = tree.xpath('//*[@id="horseTable"]') 
print(temp) 

Bitte helfen Sie!

Antwort

0

Ich würde Ihnen empfehlen, sehr requests zum Schaben und beautifulsoup für die Analyse zu verwenden.

Hier ist ein Beispiel:

import bs4 
import requests 

content = requests.get("http://bet.hkjc.com/racing/index.aspx?date=22-01-2017&venue=ST&raceno=1&lang=en").text # Get page content 
soup = bs4.BeautifulSoup(content, 'lxml') # Parse page content 

table = soup.find('table', {'id': 'horseTable'}) # Locate that table tag 
rows = table.find_all('tr') # Find all row tags in that table 

for row in rows: 
    columns = row.find_all('td') # Find all data tags in each column 

    for column in columns: 
     print column.text.strip(), # Output data in each column 

    print '\n', 

Der Ausgang:

T/P No. Colour Horse Draw Wt. Jockey Trainer Body Wt. Rtg. Gear Last 6 Runs 
1 HEALTHY LUCK 3 133 D Whyte K L Man 59 1 
2 GRACE HEART 11 130 C Y Ho (-2) C Fownes 56 B 12/8/9/11/7/7 
3 CITY LEGEND 7 126 K Teetan T P Yung 52 
4 GENERAL O'REILLY 4 126 K C Ng (-5) Y S Tsui 52 
5 JOLLY AMBER 9 126 O Murphy P F Yiu 52 B1 
6 KEEP MOVING 12 126 N Callan P F Yiu 52 
7 LUNAR ZEPHYR 13 126 M L Yeung (-2) T P Yung 52 V1 
8 MERRYGOWIN 5 126 Z Purton P O'Sullivan 52 
9 VICTORY MUSIC 8 126 T Berry J Moore 52 SR 10 
10 VITAL SPRING 1 126 J Moreira J Size 52 
11 PRINCE HARMONY 14 122 S de Sousa W Y So 48 H/P 9/6/10 
12 FUN MANAGER 6 120 T H So (-2) C H Yip 46 10/9/10/14/8/10 
13 MASSIVE MOVE 10 118 K K Chiong (-5) L Ho 44 V 3/8/6/3/7/5 
14 HAPPY SOUND 2 116 H W Lai A Lee 42 E-/B/TT 12/11/11/5/9/1 


Standby Horse 
T/P No. Horse Wt. Trainer Body Wt. Rtg. Gear Last 6 Runs 
1 BELOVED 131 P F Yiu 57 H 11 
2 EXPONENTS 124 Y S Tsui 50 B 7/7 
Verwandte Themen