您不能直接对进行理解
OrderedDict。不过,您可以在的构造函数中使用生成器
OrderedDict。
尝试以下尺寸:
import requestsfrom bs4 import BeautifulSoupfrom collections import OrderedDictsoup = BeautifulSoup(html, 'html.parser')tables = soup.find_all('table')rows = tables[1].find_all('tr')t_data = OrderedDict((row.th.text, row.td.text) for row in rows if row.td)


