【发布时间】:2021-01-24 22:48:56
【问题描述】:
response = requests.get(url)
bs = BeautifulSoup(response.text)
rows = bs.find('table', {'class': "infobox"}).find_all('tr')
list1 = []
for i,tr in enumerate(rows):
cells = tr.find_all('td')
if len(cells) == 2:
list1.append(cells[0].text.strip(":"))
list1.append(cells[1].text.strip('\n'))
res_dct = {list1[i]: list1[i + 1] for i in range(0, len(list1), 2)}
print (res_dct)
在rows = bs.find('table', {'class': "infobox"}).find_all('tr') 行中,我可以在哪里添加 features="html.parser?
【问题讨论】:
-
创建
soup对象时添加bs = BeautifulSoup(response.text, 'html.parser' )
标签: python beautifulsoup code-formatting