BeautifulSoup获取字符串之间的链接

问题描述 投票:1回答:1

所以我正在使用BS4从网站中获取以下内容:

<div>Some TEXT with <a href="some Link">some LINK</a>
and some continuing TEXT with following <a href="some Link">some LINK</a> inside.</div>

我需要得到的是:

"Some TEXT with some LINK ("https// - actual Link") and some continuing TEXT with following some LINK ("https//- next Link) inside."

我现在正在为此苦苦挣扎一段时间,不知道如何到达……在[:]之前,之后,之间,之间进行了各种尝试,以将所有数组内传递方法整合在一起。

我希望有人可以帮助我,因为我是Python的新手。预先感谢。

python string beautifulsoup hyperlink between
1个回答
0
投票

您可以将str.joinsoup.contents一起使用迭代:


-1
投票

使用bs4.element.NavigableString并产生值。

© www.soinside.com 2019 - 2024. All rights reserved.