简体   繁体   English

美丽的汤什么也没回报

[英]Beautiful Soup returning nothing

Hi I am working on a project for my school that involves scraping off the HTML. 嗨,我正在为我学校的一个项目工作,涉及刮掉HTML。

However I get none returned when I look for tables. 但是,当我查找表时,我什么也没有返回。 Here is the segment that experiences the issue. 这是遇到问题的部分。

If you need more info I'd be happy to give it to you 如果您需要更多信息,我很乐意将其提供给您

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 is expecting a String of HTML. BeautifulSoup期望使用HTML字符串。 What you provide is a response object. 您提供的是一个响应对象。

fetch the html from the response: 从响应中获取html:

 html = page.read()

and then hand html over to beautifulsoup or pass it directly however you like. 然后将html移交给beautifulsoup或根据需要直接将其传递。

In addition id would be advisable to read the following two links: 另外,建议您阅读以下两个链接以获取ID:

urllib2 documentation urllib2文档

BeautifulSoup documentation BeautifulSoup文档

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

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