使用 BeautifulSoup 解析值
我想使用 python 从所有这些 html 中获取 src url。
我有这段代码来获取文本:
avatar = html.find(class_ = "image-container image-container-player image-container-bigavatar")
print(avatar)
<div class="image-container image-container-player image-container-bigavatar"><a href="/players/1227965603"><img alt="twitch.tv/gh0stluko" class="image-player image-bigavatar" data-tooltip-url="/players/1227965603/tooltip" rel="tooltip-remote" src="https://steamcdn-a.akamaihd.net/steamcommunity/public/images/avatars/b6/b6e83cac75233208d4bb79811d768fdf17dbd46e_full.jpg" title="twitch.tv/gh0stluko"/></a></div>
I want to get src
url from all this html using python.
I had this code to get text:
avatar = html.find(class_ = "image-container image-container-player image-container-bigavatar")
print(avatar)
<div class="image-container image-container-player image-container-bigavatar"><a href="/players/1227965603"><img alt="twitch.tv/gh0stluko" class="image-player image-bigavatar" data-tooltip-url="/players/1227965603/tooltip" rel="tooltip-remote" src="https://steamcdn-a.akamaihd.net/steamcommunity/public/images/avatars/b6/b6e83cac75233208d4bb79811d768fdf17dbd46e_full.jpg" title="twitch.tv/gh0stluko"/></a></div>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
假设您只想查找图像,请将
"img"
添加为find()
的第一个参数。然后就可以直接查看
["src"]
属性:Assuming you only want to find images, add
"img"
as the first argument tofind()
.Then you can look at the
["src"]
attribute directly: