このような感じでしょうか?
python
1from bs4 import BeautifulSoup
2from bs4.element import NavigableString
3
4html = '''
5<html>
6 <head></head>
7 <body>
8 <td><strong>三菱<strong>UFJ<br/>
9 モルガン・<br/>
10 スタンレー証券</td>
11 </body>
12<html>
13'''
14
15soup = BeautifulSoup(html, 'lxml')
16print('>>> before\n', soup)
17
18# strong タグを削除
19[tag.replaceWithChildren() for tag in soup.findAll('strong')]
20
21# br タグ直後の改行を削除
22for tag in soup.findAll('br'):
23 if isinstance(tag.next_sibling, NavigableString):
24 text = tag.next_sibling.strip()
25 tag.next_sibling.replace_with(text)
26
27# br タグを削除
28[tag.replaceWithChildren() for tag in soup.findAll('br')]
29
30print('>>> after\n', soup)
output
1>>> before
2 <html>
3<head></head>
4<body>
5<td><strong>三菱<strong>UFJ<br/>
6 モルガン・<br/>
7 スタンレー証券</strong></strong></td>
8</body>
9</html>
10
11>>> after
12 <html>
13<head></head>
14<body>
15<td>三菱UFJモルガン・スタンレー証券</td>
16</body>
17</html>
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/10/03 15:57
2018/10/03 16:22
2018/10/04 00:12
2018/10/04 02:27
2018/10/04 15:10
2018/10/04 15:18 編集
2018/10/05 15:59