[英]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:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.