Python 3.x 如何删除“\n\r\n“;在输出中为一组
我有这样的代码Python 3.x 如何删除“\n\r\n“;在输出中为一组,python-3.x,Python 3.x,我有这样的代码 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.findAl
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': 'עִנְיָן שֶׁנִּ...................................................................................................................................................................................................................................................
我不想从输出中删除\n\t,因为我的文件将被清除。我该如何做????拆分单词并用空格连接它们
'english':" ".join(all_td[1].text.split())
这会删除所有的“\n”、“r”和“。您能输出
all\u td
吗,或者all\u td[1]
看起来怎么样?看起来像本周四晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚晚א,
……这里有很多代码