我正在尝试从网站获取图像的src
属性。问题是它返回一些编码文本,而不是src
。编码文本为:
data:image/gif;base64,R0lGODdhFQAXAPAAANba3wAAACwAAAAAFQAXAAACFISPqcvtD6OctNqLs968+w+GolUAADs=
该网站是here
我的代码是:
import requests
from bs4 import BeautifulSoup as bs
url = 'https://www.redbubble.com/shop/shower-curtains?page={}'
count = 0
for page in range(1,205):
response = requests.get(url.format(page))
if response.ok:
contents = bs(response.text , 'lxml')
curtains = contents.find_all('a' , class_='styles__link--2sYi3')
for curtain in curtains:
count += 1
name = curtain.find('span' , class_='styles__text--NLf2i styles__display6--uq_8G styles__block--3OueG').text.strip()
price = curtain.find('span' , class_='styles__text--NLf2i styles__body--3bpp7 styles__block--3OueG').text.strip()
image_url = curtain.find('img' , class_='styles__image--2CwxX styles__productImage--3ZNPD styles__rounded--1lyoH styles__fluid--3dxe-').get('src')
print('*'*20 , count , '*'*20)
print('Name: {}'.format(name))
print('Price: {}'.format(price))
print('Image Url: {}'.format(image_url))
如何从图像中获取src
属性,如下所示:
https://ih1.redbubble.net/image.887440492.3733/ur,shower_curtain_closed,square,600x600.1u2.jpg
每页包含100多幅产品图片。前16个返回有效的src
链接,而其余的返回编码文本,与上面的一样
输出:
相关问题 更多 >
编程相关推荐