Beautiful Soup 的 unwrap()
方法從元素中刪除標簽並返回它。
例子
考慮以下 html:
html = '<a href="https://skytowner.com/">Linking to <i>skytowner.com</i></a>'
soup = BeautifulSoup(html)
a_tag = soup.a
a_tag.i.unwrap()
<i></i>
在這裏,我們從 a_tag.i
中刪除標簽,即 <i></i>
,僅保留標簽 skytowner.com
內的內容。
如果我們現在在執行解包後顯示a_tag
:
a_tag.i.unwrap()
a_tag
<a href="https://skytowner.com/">Linking to skytowner.com</a>
我們可以看到<i>
標簽不再存在於<a>
標簽中。
相關用法
- Python unittest.mock.AsyncMock.assert_awaited_once_with用法及代碼示例
- Python unittest.TestCase.assertWarnsRegex用法及代碼示例
- Python unittest.mock.Mock.__class__用法及代碼示例
- Python Pandas unique方法用法及代碼示例
- Python unittest.TestCase.assertRaisesRegex用法及代碼示例
- Python unittest.mock.call用法及代碼示例
- Python unittest.mock.Mock.method_calls用法及代碼示例
- Python unittest.mock.Mock.call_args_list用法及代碼示例
- Python unittest.mock.AsyncMock.assert_any_await用法及代碼示例
- Python unittest.mock.Mock.assert_called用法及代碼示例
- Python unittest.TestCase.assertRaises用法及代碼示例
- Python unittest.TestCase.tearDownClass用法及代碼示例
- Python unittest.mock.Mock.assert_not_called用法及代碼示例
- Python unittest.IsolatedAsyncioTestCase用法及代碼示例
- Python NumPy unique方法用法及代碼示例
- Python unittest.TestCase.setUpClass用法及代碼示例
- Python unittest.mock.Mock.mock_calls用法及代碼示例
- Python unittest.mock.Mock.call_args用法及代碼示例
- Python unittest.mock.Mock.assert_has_calls用法及代碼示例
- Python unittest.mock.AsyncMock.assert_awaited_with用法及代碼示例
- Python unittest.mock.Mock.configure_mock用法及代碼示例
- Python unittest.mock.Mock.called用法及代碼示例
- Python unittest.mock.Mock.side_effect用法及代碼示例
- Python unittest.mock.Mock.assert_called_once_with用法及代碼示例
- Python unittest.mock.AsyncMock.assert_has_awaits用法及代碼示例
注:本文由純淨天空篩選整理自Arthur Yanagisawa大神的英文原創作品 BeautifulSoup | unwrap method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。