我有這段代碼。我想在每個細節的'details'數組中插入一個新的鍵值對(mine_id,123456)。我不知道如何做到這一點。花了大約5個小時嘗試一下。我是Ruby新手,非常感謝您的幫助。紅寶石 - 插入散列值
再次感謝 問候
mineId = "123456"
doc = Nokogiri::HTML.parse($browser.html)
rows = doc.xpath(".//*[@id='content']/table/tbody/tr")
details = rows.collect do |row|
detail = {}
[
[:prod_year, 'td[1]/font/text()'],
[:prod_qtr, 'td[2]/font/text()'],
[:subunit_cd, 'td[3]/font/text()'],
[:subunit, 'td[4]/font/text()'],
[:qtr_hrs, 'td[5]/font/text()'],
[:coal_prod, 'td[6]/font/text()'],
[:avg_emp_cnt, 'td[7]/font/text()'],
].each do |name, xpath|
detail[name] = row.at_xpath(xpath).to_s.strip
end
detail
end
只是'detail [:mineId] =「123456」;詳細信息' –