Q:

HTML table tags parsing with Beautiful soup

I have the following task, to find one certain table in HTML page with tag '<table' and attribute 'class= wikitable collapsible collapsed' (only second one from the start), using BeautifulSoup.  When I organize attribute structure like dictionary, the program with no reason read the all the  attributes as one item.  I need them to be separated like dictionary objects to extract only 2nd item.  This is the code:
from urllib.request import urlopen

from bs4 import BeautifulSoup

response = 
urlopen('file:///C:/Users/User/Documents/Visual%20Studio%202017/DjangoWebProject1/DjangoWebProject1/app/New-York%20(1).html')

html = response.read().decode('utf-8')

soup = BeautifulSoup(html, 'html.parser')

your_dictionary={}

for node in soup.find_all('table',attrs={'class':'wikitable collapsible collapsed'}):

    your_dictionary[node] = node

    print(your_dictionary[2])

A:

The code is searching for all tables (That is soup.find_all('table').  The page has 4 matches.  Therefore you'll need to target the particular table.  This can be done using indexes.  Also to extract the results to a dictionary, you'll need to scrape the tr & td elements. 
Below should scrape the row Population change, 2000 to 2010 and convert to dictionary. ( Note: I may have misunderstood what the output should be, but there should be enough to tweek it)
from urllib.request import urlopen
from bs4 import BeautifulSoup

response = urlopen('file:///C:/Users/User/Documents/Visual%20Studio%202017/DjangoWebProject1/DjangoWebProject1/app/New-York%20(1).html')

html = response.read().decode('utf-8')
soup = BeautifulSoup(html, 'html.parser')

tables = soup.find_all('table',attrs={'class':'wikitable collapsible collapsed'})
table_city_and_state = tables[1] # find second table

tr_city_and_state = table_city_and_state.find_all('tr')
tr_population_change = tr_city_and_state[3] # find second table row, which is the 4th as the frst 2 are headers. 
tds_population_change = tr_population_change.find_all('td')

your_dictionary = {
    "city": tds_population_change[1].text.strip(),
    "state": tds_population_change[2].text.strip(),
    "country": tds_population_change[3].text.strip()
}

print(your_dictionary)

Output:
{'city': '+2.1%', 'state': '+2.1%', 'country': '+9.7%'}

Alternative approach
When scraping a website, the html can change at any point.  For example the table positions could be swapped around.  Therefore it's recommend to positively identify the data.  One way can be using the name of table headers and the table row name.  For example:
from urllib.request import urlopen
from bs4 import BeautifulSoup

response = urlopen('file:///C:/Users/User/Documents/Visual%20Studio%202017/DjangoWebProject1/DjangoWebProject1/app/New-York%20(1).html')
table_header = 'City compared to State & U.S.'
table_row_name = 'Population change, 2000 to 2010'

def find_table_by_header(table, header_text):
    return table if table.find('th') and table.find('th').text.strip() == header_text else None

def find_tablerow_by_title(table, table_row_name):
    trs = table.find_all('tr')
    results = [x for x in trs if x.find('td') and x.find('td').text.strip() == table_row_name]
    return None if not results else results[0]

html = response.read().decode('utf-8')
soup = BeautifulSoup(html, 'html.parser')

tables = soup.find_all('table', attrs={'class':'wikitable collapsible collapsed'})
table_city_and_state = [tbl_result for tbl_result in [find_table_by_header(tbl, table_header) for tbl in tables] if tbl_result][0]
tr_population_change = [tbl_result for tbl_result in [find_tablerow_by_title(table_city_and_state, table_row_name) for tbl in tables] if tbl_result][0]
tds_population_change = tr_population_change.find_all('td')

your_dictionary = {
    "city": tds_population_change[1].text.strip(),
    "state": tds_population_change[2].text.strip(),
    "country": tds_population_change[3].text.strip()
}

print(your_dictionary)

Output:
{'city': '+2.1%', 'state': '+2.1%', 'country': '+9.7%'}

