Итак, у меня есть общий словарь, который установлен пустым, и я добавил к нему URL-адрес и длительность, теперь в словаре несколько URL-адресов и длительностей, все длительности хранятся в списке, я пытаюсь Доступ к каждому отдельному списку, чтобы добавить числа в них вместе, но я не могу получить к нему доступ, кто-нибудь знает, как?
import time
import unittest
import json
from selenium import webdriver
class Tester(unittest.TestCase):
"doc string"
def setUp(self):
"doc string"
self.driver = webdriver.Chrome("/Users/tamerjar/Desktop/chromedriver")
self.driver.implicitly_wait(30)
self.verificationErrors = []
def test_er(self):
"doc string"
driver = self.driver
# This is the total dictionary where im trying to access the ['duration']
total = {}
print("total" + str(total))
durations = []
with open('output.txt', 'w') as json_file:
for result in range(10):
driver.get("https://en.wikipedia.org/wiki/Software_metric")
result = driver.execute_script('return window.performance.getEntries()')
print(result)
for current in result:
#This is where i appended to the total
url = current['name']
current_list = total.get(url, [])
current_list.append(current['duration'])
total[url] = current_list
print("current list" + str(current_list))
print("total" + str(total))
print(current['name'])
print(current['duration'])
print(current.keys())
json_file.write(f"{current['name']}, {current['duration']}\n")
print("Total final : " + str(total))
# with open('mycsv.csv', 'w') as csv_file:
# for key in total.keys():
# csv_file.write(f'{key}, {average}')
with open('json_output' + '.json', 'w', encoding='utf-8') as f:
json.dump(result, f, ensure_ascii=False, indent=4)
def tearDown(self):
self.driver.quit()
self.assertEqual([], self.verificationErrors)
if __name__ == "__main__":
unittest.main()