Python和BeautifulSoup的新手,我试图从网站刮比赛细节,以显示在我的本地俱乐部网站。BeautifulSoup刮从远程站点显示在本地网站的详细信息
这是到目前为止我的代码:
import urllib2
import sys
import os
sys.path.insert(0, os.path.abspath(os.path.dirname(__file__)))
from BeautifulSoup import BeautifulSoup
# Road
#cyclelab_url='http://www.cyclelab.com/OnLine%20Entries.aspx?type=Road%20Events'
# MTB
cyclelab_url='http://www.cyclelab.com/OnLine%20Entries.aspx?type=Mountain%20Biking%20Events'
response = urllib2.urlopen(cyclelab_url)
html = response.read()
soup = BeautifulSoup(html)
event_names = soup.findAll(attrs= {"class" : "SpanEventName"})
for event in event_names:
txt = event.find(text=True)
print txt
event_details = soup.findAll(attrs= {"class" : "TDText"})
for detail in event_details:
lines=[]
txt_details = detail.find(text=True)
print txt_details
这将打印事件名称和事件的详细信息,我想要做的就是,打印事件名称,然后在它下面该事件的事件细节。这看起来应该很简单,但我很难过。
对于页面上的每个事件,将打印出来的事件名称,然后* all * events的详细信息 - 我认为这不是@ user621024想要的内容... – 2011-02-28 12:20:15
您是对的。我不应该在其他事情之间急于回答问题,也不要对其进行测试。 upvoted你的答案。 – dermatthias 2011-02-28 13:24:52