gpt4 book ai didi

python - 如何在python上获取子链接

转载 作者:太空宇宙 更新时间:2023-11-03 15:53:17 24 4
gpt4 key购买 nike

我有这个代码:

<div class="class_one"><a href="link"></a></div>

我这样做:

soup = BeautifulSoup(path.text, 'html.parser')
for link in soup.find_all("div", { "class" : "class_one"}):

我使用正则表达式来获取 href 链接。 Beautiful Soup 还有其他解决方案吗?

最佳答案

for link in soup.find_all("div", { "class" : "class_one"}):
a = link.next_element
print(a)

输出:

<a href="link"></a>

字符串或标签的 .next_element 属性指向随后立即解析的内容。

关于python - 如何在python上获取子链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41045446/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com