使用 bs4 从网站抓取图像时遇到问题

时间:2021-01-01 21:43:27

标签: python beautifulsoup

嘿,我似乎无法从这个网站上抓取图片

https://www.nike.com/gb/w/new-mens-shoes-3n82yznik1zy7ok

我正在使用以下代码

product.find('img', {'class': 'css-1fxh5tw product-card__hero-image'})['src']]

它返回这个

data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7

1 个答案:

答案 0 :(得分:1)

你的代码没有错。我已经提取了图像

import requests
from bs4 import BeautifulSoup

url ="https://www.nike.com/gb/w/new-mens-shoes-3n82yznik1zy7ok"

response = requests.get(url)

soup = BeautifulSoup(response.text, 'lxml')

images = soup.find_all('img', {'class':'css-1fxh5tw product-card__hero-image'},src=True)
for i in images:
    if 'data:image' not in i['src']:
        print(i['src'])