繁体   English   中英

如何获得“src=...”的 url?

[英]How can I get the url of “src=…”?

我正在尝试遍历此处的所有img类,但我不确定如何获取src=链接

import requests
from bs4 import BeautifulSoup

url = 'https://giphy.com/search/anxiety'
html = requests.get(url).text
soup = BeautifulSoup(html, "html.parser")
gifs = soup.findAll("img", attrs={"class": "giphy-gif-img"})

for gif in gifs:
    print(gif.get('image-src'))

在最后一行中,您可以使用gif.get('src') 但是, gifs是空的,因为页面上没有class=giphy-gif-img的图像。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM