首页 > 解决方案 > 删除 beautifulSoup 输出中 {} 括号之间的所有内容

问题描述

我想解析文本表单 html 页面。一些页面返回文本,但也有一些{}我不想要的文本和字符。

我试过了:

import re
from bs4 import BeautifulSoup

art = soup.find_all('p')
for clean in art: 
    x = clean.text.encode('ascii', 'ignore').decode('ascii')
    x = re.sub("([{]).*?([}])", "\g<1>\g<2>", x)
    print(x.strip())

但是没有雪茄...

标签: beautifulsoup

解决方案


推荐阅读