2017-03-21 117 views

回答

0

只需设置tag.string为空字符串,或者使用tag.string.replace_with()

bs = BeautifulSoup(html) 
    for tag in bs.find_all('span'): 
     # Strip all text by setting it to an empty string 
     tag.string = "" 
     # Or strip all text by replacing the string 
     tag.string.replace_with("") 
相关问题