繁体   English   中英

美丽的汤什么也没回报

[英]Beautiful Soup returning nothing

嗨,我正在为我学校的一个项目工作,涉及刮掉HTML。

但是,当我查找表时,我什么也没有返回。 这是遇到问题的部分。

如果您需要更多信息,我很乐意将其提供给您

from bs4 import BeautifulSoup
import urllib2
import datetime

#This section determines the date of the next Saturday which will go onto the end of     the URL 
d = datetime.date.today() 
while d.weekday() != 5:
    d += datetime.timedelta(1)

#temporary logic for testing when next webpage isn't out
d = "2013-06-01"

#Section that scrapes the data off the webpage
url = "http://www.sydgram.nsw.edu.au/co-curricular/sport/fixtures/" + str(d) + ".php"
page = urllib2.urlopen(url)
soup = BeautifulSoup(page)
print soup
#Section that grabs the table with stuff in it
table = soup.find('table', {"class": "excel1"})
print table

BeautifulSoup期望使用HTML字符串。 您提供的是一个响应对象。

从响应中获取html:

 html = page.read()

然后将html移交给beautifulsoup或根据需要直接将其传递。

另外,建议您阅读以下两个链接以获取ID:

urllib2文档

BeautifulSoup文档

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM