我试图从似乎是ajax webapage的数据中删除数据。数据每秒自动刷新。
http://daytonama.clubspeedtiming.com/sp_center/livescore.aspx
如果我选择了正确的下拉菜单,或者页面正在更改为我需要抓取的数据,我似乎无法解决问题。
由于
!/usr/bin/env python
import mechanize
from bs4 import BeautifulSoup
import re
import urllib2
#import html2text
import time
# Set credentials
venue = "sp" # Manchester (ma), Milton Keynes (mk), Sandown Park (sp), Tamworth (ta)
track = "3" # Manchester (3), Milton Keynes (1)
# Open new browser
br = mechanize.Browser()
# Target live timing page
resp = br.open("http://daytona"+ venue +".clubspeedtiming.com/sp_center/livescore.aspx")
html = resp.read()
# Grab live data table
soup = BeautifulSoup(html, "html5lib")
# Select track layout
select_node = soup.findAll('select', attrs={'name': 'ddlTrack'})
if select_node:
for option in select_node[0].findAll('option'):
print ''
#print option.text
br.select_form( name = 'form1' )
br.form['ddlTrack'] = [track]
grid = soup.find("div", { "id" : "grid" })
print ''.join(map(str, grid.contents))