我有一个包含电脑游戏的链接,对于每个游戏,我都希望提取具有最高分辨率的产品图像,而不是所有img标签。到目前为止,我已经:
#GET ALL IMG TAGS
img_tags = soup2.find_all('img')
#CREATE LIST WITH IMG TAGS
urls_img = [img['src'] for img in img_tags]
#CHECK EACH IMG TAG
for murl in urls_img:
filename = re.search(r'/([\w_-]+[.](jpg|png))$', murl)
if filename is not None:
with open(filename.group(1), 'wb') as f:
if 'http' not in murl:
murl = '{}{}'.format(site, murl)
#GET THE RESPONSE OF IMG URL
response = requests.get(murl)
if response.status_code == 200:
f.write(response.content)
编辑:在讨论之后,下面将获取初始产品URL(不包括占位符),并访问每个页面以查找最大的图像。最大的图像有一个属性
['data-large_image']
。你知道吗我使用
Session
来提高重用连接的效率。你知道吗以前的答案(基于所有产品的原始单一url):
尝试下面的方法,在每个列表中查找
srcset
属性。如果存在,则采用列出的最后一个src
链接(按升序分辨率排序),否则采用src
属性。你知道吗我发现这也许更容易解决我的问题
即使我不知道它是否更快
相关问题 更多 >
编程相关推荐