python - 为什么我的解析图像链接以 base64 格式输出
问题描述
我试图解析来自网站的图像链接。当我检查网站上的链接时,它是这个:https ://static.nike.com/a/images/c_limit,w_592,f_auto/t_product_v1/df7c2668-f714-4ced-9f8f-1f0024f945a9/chaussure-de- Basketball-zoom-freak-3-MZpJZF.png但是当我用我的代码解析它时,输出是data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7
.
from bs4 import BeautifulSoup
import requests
source = requests.get('https://www.nike.com/fr/w/hommes-chaussures-nik1zy7ok').text
soup = BeautifulSoup(source, 'lxml')
pair = soup.find('div', class_='product-card__body')
image_scr = pair.find('img', class_='css-1fxh5tw product-card__hero-image')['src']
print(image_scr)
我认为代码不是问题,但我不知道是什么导致链接以 base64 格式出现。那么我如何设置代码以将链接呈现为 .png ?
解决方案
由于要抓取 src 意思是图片数据,所以使用请求从服务器下载数据,需要使用.content
如下格式:
source = requests.get('https://www.nike.com/fr/w/hommes-chaussures-nik1zy7ok').content
推荐阅读
- android - Android 应用程序在设备中安装了 2 次
- jenkins - Jenkins 使用我的 git 项目创建 jar
- ios - 如何设置纵向和横向约束
- leaflet - 如何设置 maxZoom 以在 18 之后使用 BING 层进行插值
- python - 形状外的距离。多边形
- javascript - SVG 和 jQuery:尽管计算正确,但多行文本不会居中
- python - 如何在训练时从 Tensorflow 重置 AdamOptimizer
- ruby-on-rails - 如何访问 ActiveRecords 关联的对象
- html - 即使没有加载图像也能显示图像圆形
- javascript - ajaxComplete() 是否适用于 trigger()?