代码:
body_text = BeautifulSoup(open(html)).text在html页面中,像1.ETA这样的行预期的metocean条件在提取时被分割成行,需要解决这个问题。
我使用了字符串格式设置条件,如
body_html = str(BeautifulSoup(open(html_file)))
body_html = body_html.replace('\n', ' ') #to remove all new lines
body_html = body_html.replace('/>', '/>\n') # add new lines so that texts from two different tags do not extracted in same line示例HTML页面:https://easyupload.io/sh02xi
是否有更好的方法来提取与我们在html中可视化的文本格式相同的文本?
发布于 2020-08-27 11:26:53
当文本需要以与html格式相同的格式提取时,html2text更适合文本提取:
h = html2text.HTML2Text()
h.body_width = 0
h.ignore_links = True
h.ignore_images = True
print(h.handle(html_string))https://stackoverflow.com/questions/63596542
复制相似问题