Q: Accessing a dictionary with tag types in BeautifulSoup For the HTML that's being parsed and put into a dictionary inside a list, I know that <th>Name</th> corresponds with a value.
It seems to be throwing a key error because it's a tag, rather than a string.
courseCode = "BSB119"

page = requests.get("https://www.qut.edu.au/study/unit?unitCode=" + courseCode)

soup = BeautifulSoup(page.content, 'html.parser')
tables = soup.find_all(class_='table assessment-item')

numOfTables = 0
list_ = []
dictionary_ = {}

for tbl in tables:
    numOfTables = numOfTables + 1
    keys = tbl.find_all('th').string
    values = tbl.find_all('td').string
    new_data = dict(zip(keys, values))
    list_.append(new_data)

for i in range(0,numOfTables):
    print(list_[i]["<th>Name</th>"])

How I convert the tag into a string so that I can access it as a dictionary key? I tried the above method, but it says I'm accessing more than one thing...

A: keys = tbl.find_all('th').string

according to the documentation, you get None if you call string on soup with more than one element. you get a keyerror because the dict is empty! rather,
keys = list(map(lambda x: x.string, tbl.findall('th')))

and same for values
