我的建築內,做下面的事情的任務的小模塊: - 讀取網頁(cavirtex.com/orderbook) - 獲得與urllib的來源和使用beautifulsoup -parse打開現在得到body.div(id='xx')
,我卡在這裏。我想重新美化結果並在更大的tr內迭代兩行td並獲取值並對它們進行求和。如果有人知道如何做到這一點,請向我解釋,因爲我在這裏呆了幾個小時。哦,這裏是我的源代碼:BeautifulSoup雙層
myurl = urllib.urlopen('http://cavirtex.com/orderbook').read()
soup = BeautifulSoup(myurl)
selling = soup.body.div(id ='orderbook_buy')
selling = str(selling)
selling = BeautifulSoup(selling)
Sresult = selling.find_all(['tr'])
amount = 30
count = 0
cadtot = 0
locamount = 0
for rows in Sresult:
#agarrar string especifico para vez
Wresult = Sresult[count]
#crear lista
Eresult = [Wresult]
Eresult = str(Eresult)
cosito = str(Eresult[count])
print cosito
count = int(count) + 1
cadtot = cadtot + locamount
謝謝Pawelmhm!這正是我需要的。 – user2542929