錯誤:剛接觸python並試圖對每15分鐘刷新一次的表進行webscrape。得到一個錯誤約需要一個字符串
C:\的Python>蟒蛇webscrape.py 回溯(最近通話最後一個): 文件 「webscrape.py」 23行,在 打印(「樞紐:」 +集線器) 類型錯誤:必須海峽,就不一一列舉
代碼:
from urllib.request import urlopen as uReq
from bs4 import BeautifulSoup as soup
my_url = 'http://www.ercot.com/content/cdr/html/real_time_spp'
# opening up connection, grabbing the web page
uClient = uReq(my_url)
page_html = uClient.read()
uClient.close()
# html parsing
page_soup = soup(page_html, "html.parser")
# grabs the market conditions
intervals = page_soup.findAll("div",{"id":"today"})
for interval in intervals:
hubs = interval.table.tr.th["class"]
price_intervals = interval.findAll("td",{"class":"labelClassCenter"})
all_prices = price_intervals[0].text
print ("hubs:" + hubs)
print ("all_prices:" + all_prices)
呀,誤差非常描述本身...樞紐是一個列表,所以你不能表現出來就像是內容....如果例如,你可以寫'print(「Hubs:」+ hubs [0])',你將得到一個結果......或者你可以使用'join',就像'print(「Hubs:」+ hubs.join (「,」))' – Hackerman