Я пытаюсь распечатать таблицу имен детей, указанную в формате списка, с помощью Beautifulsoup.
google-python-упражнения / google-python-упражнения / babynames / baby1990.html (HTML-страница - это скриншот фактического URL-адреса)
После извлечения таблицы с помощью urllib.request и ее синтаксического анализа с BeautifulSoup мне удалось распечатать данные внутри каждой строки таблицы, но я получаю неправильную информациювыход.
вот мой код:
right_table = soup.find('table',attrs = {"summary" : "Popularity for top 1000"})
table_rows = right_table.find_all('tr')
for tr in table_rows:
td = tr.find_all('td')
row = [i.text for i in td]
print(row)
Предполагается распечатать 1 список, содержащий все данные в строках. Однако я получаю несколько списков, каждый новый список начинается с одногоменьше записей в нем
Вроде как:
['997', 'Eliezer', 'Asha', '998', 'Jory', 'Jada', '999', 'Misael', 'Leila', '1000', 'Tate', 'Peggy', 'Note: Rank 1 is the most popular,\nrank 2 is the next most popular, and so forth. \n']
['998', 'Jory', 'Jada', '999', 'Misael', 'Leila', '1000', 'Tate', 'Peggy', 'Note: Rank 1 is the most popular,\nrank 2 is the next most popular, and so forth. \n']
['999', 'Misael', 'Leila', '1000', 'Tate', 'Peggy', 'Note: Rank 1 is the most popular,\nrank 2 is the next most popular, and so forth. \n']
['1000', 'Tate', 'Peggy', 'Note: Rank 1 is the most popular,\nrank 2 is the next most popular, and so forth. \n']
['Note: Rank 1 is the most popular,\nrank 2 is the next most popular, and so forth. \n']
Как напечатать только один список?