我不知道是否有这样的东西 - 但我正在尝试做一个有序字典解析。然而它似乎不起作用?
import requests
from bs4 import BeautifulSoup
from collections import OrderedDict
soup = BeautifulSoup(html, 'html.parser')
tables = soup.find_all('table')
t_data = OrderedDict()
rows = tables[1].find_all('tr')
t_data = {row.th.text: row.td.text for row in rows if row.td }
现在它被留作普通字典推导式(我也省略了通常的 requests to soup 样板)。
任何想法?