gpt4 book ai didi

Python - 如何在没有selenium的情况下使用BeautifulSoup提取href(onclick)

转载 作者:行者123 更新时间:2023-12-01 09:32:33 25 4
gpt4 key购买 nike

这是元素。

<img src="http://dcimg6.dcinside.co.kr/viewimage.php?id=2fbcc323e7d334aa51b1d3a240&amp;no=24b0d769e1d32ca73fef84fa11d028318f52c0eeb141bee560297996d466c894cf2d16427672bba3d66d67f244141456484cb174854719ce631af568a8c297d4e29cc59286bf0d77bcf8d9267e7297e17913fdd84522b3d3" style="cursor:pointer;" onclick="javascript:imgPop('http://image.dcinside.com/viewimagePop.php?id=2fbcc323e7d334aa51b1d3a240&amp;no=24b0d769e1d32ca73fef84fa11d028318f52c0eeb141bee560297996d466c894cf2d16427672bba3d66d67f24450460016bd8e2258cb95ccf2b058e84f237054da6dbbc48af67310bf0bff50c529f1331053edf6','image','fullscreen=yes,scrollbars=yes,resizable=no,menubar=no,toolbar=no,location=no,status=no');">

我想在这里提取“http://image.dcinside.com/viewimagePop.php?id=2fbcc323e7d334aa51b1d3a240&no=24b0d769e1d32ca73fef84fa11d028318f52c0eeb141bee560297996d466c894cf2d16427672bba3d66d67f24450460016bd8e2258cb95ccf2b058e84f237054da6dbbc48af67310bf0bff50c529f1331053edf6

如何提取?

最佳答案

这应该适用于 BeautifulSoup v3 和 v4。

content = """
<img src="http://dcimg6.dcinside.co.kr/viewimage.php?id=2fbcc323e7d334aa51b1d3a240&amp;no=24b0d769e1d32ca73fef84fa11d028318f52c0eeb141bee560297996d466c894cf2d16427672bba3d66d67f244141456484cb174854719ce631af568a8c297d4e29cc59286bf0d77bcf8d9267e7297e17913fdd84522b3d3" style="cursor:pointer;" onclick="javascript:imgPop('http://image.dcinside.com/viewimagePop.php?id=2fbcc323e7d334aa51b1d3a240&amp;no=24b0d769e1d32ca73fef84fa11d028318f52c0eeb141bee560297996d466c894cf2d16427672bba3d66d67f24450460016bd8e2258cb95ccf2b058e84f237054da6dbbc48af67310bf0bff50c529f1331053edf6','image','fullscreen=yes,scrollbars=yes,resizable=no,menubar=no,toolbar=no,location=no,status=no');">
"""

soup = BeautifulSoup(content)

onclick = soup.find('img').get('onclick')

js_item = onclick.split(',')[0]

link = js_item.replace('javascript:imgPop(', '').replace("'", "")

关于Python - 如何在没有selenium的情况下使用BeautifulSoup提取href(onclick),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49838179/

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