如何从所有文本中删除上标?我下面的代码可以获取所有可见的文本,但是脚注的上标使事情变得混乱。如何删除它们?
例如Active accounts (1),(2),(1),(2)是可见的上标。
from bs4 import BeautifulSoup
from bs4.element import Comment
import requests
f_url='https://www.sec.gov/Archives/edgar/data/1633917/000163391718000094/exhibit991prq12018pypl.htm'
def tag_visible(element):
if element.parent.name in ['style', 'script', 'head', 'title', 'meta', '[document]']:
return False
if isinstance(element, Comment):
return False
return True
def text_from_html(body):
soup = BeautifulSoup(body, 'html.parser')
texts = soup.findAll(text=True)
visible_texts = filter(tag_visible, texts)
return u" ".join(t.strip() for t in visible_texts)
html = requests.get(f_url)
text= text_from_html(html.text)
慕田峪4524236
相关分类