python - 抓取 img src 输出到 base64

标签 python html python-2.7 beautifulsoup base64

我正在尝试仅抓取 https:// 链接:

src ="https://static.daraz.com.bd/p/apple-1088-5942-1-catalog.jpg"

使用BeautifulSoup4 Python 库从以下代码中获取。

<div class="image-wrapper default-state">
      <img class="lazy image -loaded" alt="Macbook Air (MD711ZA/B) - Aluminum - Laptop - Dual-Core Intel Core i5 - 4GB RAM - 128GB HDD - 11.6&amp;#039;&amp;#039; LED - Intel HD Graphics 5000 - Mac OS X Mountain Lion 10.8" data-image-vertical="1" width="176" height="220" src="https://static.daraz.com.bd/p/apple-1088-5942-1-catalog.jpg" data-sku="AP113ELAA1XBNAFAMZ" data-placeholder="placeholder_daraz.jpg" style="display: inline-block;">
      <noscript>&lt;img src="https://static.daraz.com.bd/p/apple-1088-5942-1-catalog.jpg" width="176" height="220" class="image" /&gt;
      </noscript>
</div>

但是我得到的输出是这样的:

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

有什么方法可以获取原始src链接吗?

BeautifulSoup 代码:

for image in soup.findAll('div', attrs={'class': 'image-wrapper default-state'}):
            print image.img['src']

相同的代码在其他站点上运行并获取 src 链接。但只有在这里它才输出为base64 格式。

最佳答案

全部转换img标记为string然后我发现tag他们使用的是 <data-img src=" ">

然后我就简单地使用了 tag并得到了我预期的输出。

for image in soup.findAll('div', attrs={'class': 'image-wrapper'}):
    print image.img['data-src']

关于python - 抓取 img src 输出到 base64,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33060997/

相关文章:

python - 在 Spark : Executor lost 中获取错误

python - 使用 Windows 绘图进行 pywinauto 测试

python - Django 1.5 : Display foreignkey values in both admin models

python - Gitlab-CI 无法满足不可满足的约束 python missing

javascript - 如何在div标签中迭代input标签并根据inputdata显示多个input标签

python - 安装 PyLucene 期间出现导入错误 : cannot import name Library,

python - 通过类属性调用的函数对象失败

html - 将图标与文本放在同一行

php - BLOB:在MySQL数据库中使用PHP存储图像

python - 函数的返回值是none