我有这样一段代码
我的输出结果如下:
from bs4 import BeautifulSoup
import requests
import re
page = open('doc1.html','rb').read()
soup = BeautifulSoup(page,'lxml')
# print(soup.prettify())
# eng = soup.find_all(string = re.compile("righteou"))
# print(eng)
# heb = soup.findAll('p',{'dir':'RTL'})
# print(heb)
list=[]
all_tr =soup.findAll('tr')
for td in all_tr:
all_td = soup.findAll('td')
d={
'hob':all_td[0].text.strip(),
'english':all_td[1].text.strip()
}
list.append(d)
print(list)
我的输出结果如下:
[{'hob': 'עִנְיָן שֶׁנִּיתְּנָה הַתּוֹרָה עַל הַר סִינַי דַּוְקָא,', 'english': '\n\r\n We need to understand\r\n \r\n
the idea that the Torah was given specifically on Mount\r\n Sinai,\r\n '}, {'hob': 'עִנְיָן שֶׁנִּיתְּנָה הַתּוֹרָה עַל הַר סִינַי דַּוְקָא,', 'english': '\n\r\n We need to understand\r\n \r\n the idea that the Torah was given specifically on Mount\r\n Sinai,\r\n '}, {'hob': 'עִנְיָן שֶׁנִּיתְּנָה הַתּוֹרָה עַל הַר סִינַי דַּוְקָא,', 'english': '\n\r\n We need to understand\r\n \r\n the idea that the Torah was given specifically on Mount\r\n Sinai,\r\n '}, {'hob': 'עִנְיָן שֶׁנִּיתְּנָה הַתּוֹרָה עַל הַר סִינַי דַּוְקָא,', 'english': '\n\r\n We need to understand\r\n \r\n the idea that the Torah was given specifically on Mount\r\n Sinai,\r\n '}, {'hob': 'עִנְיָן שֶׁנִּיתְּנָה הַתּוֹרָה עַל הַר סִינַי דַּוְקָא,', 'english': '\n\r\n We need to understand\r\n \r\n the idea that the Torah was given specifically on Mount\r\n Sinai,\r\n '}, {'hob': 'עִנְיָן שֶׁנִּיתְּנָה הַתּוֹרָה עַל הַר סִינַי דַּוְקָא,', 'english': '\n\r\n We need to understand\r\n \r\n the idea that the Torah was given specifically on Mount\r\n Sinai,\r\n '}, {'hob': 'עִנְיָן שֶׁנִּיתְּנָה הַתּוֹרָה עַל הַר סִינַי דַּוְקָא,', 'english': '\n\r\n We need to understand\r\n \r\n the idea that the Torah was given specifically on Mount\r\n Sinai,\r\n '}, {'hob': 'עִנְיָן שֶׁנִּיתְּנָה הַתּוֹרָה עַל הַר סִינַי דַּוְקָא,', 'english': '\n\r\n We need to understand\r\n \r\n the idea that the Torah was given specifically on Mount\r\n Sinai,\r\n '}, {'hob': 'עִנְיָן שֶׁנִּיתְּנָה הַתּוֹרָה עַל הַר סִינַי דַּוְקָא,', 'english': '\n\r\n We need to understand\r\n \r\n the idea that the Torah was given specifically on Mount\r\n Sinai,\r\n '}, {'hob': 'עִנְיָן שֶׁנִּ...................................................................................................................................................................................................................................................
我想要将输出中的换行符和制表符去掉,这样我的文件就会变得更加清晰了。我该如何做到这一点?
all_td
的内容或者all_td[1]
是什么样子吗? - Dmitriy Kisil