本站消息

  出租广告位,需要合作请联系站长

  今日名言-想象你自己对困难作出的反应,不是逃避或绕开它们,而是面对它们,同它们打交道,以一种进取的和明智的方式同它们奋斗 。——马克斯威尔·马尔兹

  今日名言-用谅解、宽恕的目光和心理看人、待人。人就会觉得葱笼的世界里,春意盎然,到处充满温暖。——蔡文甫


+关注
已关注

分类  

暂无分类

标签  

暂无标签

日期归档  

暂无数据

python 通过srcset属性获取最高像素图片

发布于2021-07-25 06:35     阅读(825)     评论(0)     点赞(7)     收藏(0)


python 通过srcset属性获取最高像素图片

例如:

<img width="600" height="900" src="https://styledumonde.com/wp-content/uploads/2021/07/Milan-SS21-day-1-by-STYLEDUMONDE-Street-Style-Fashion-Photography_95A3263-600x900.jpg" class="attachment-original size-original wp-post-image" alt="" loading="lazy" srcset="https://styledumonde.com/wp-content/uploads/2021/07/Milan-SS21-day-1-by-STYLEDUMONDE-Street-Style-Fashion-Photography_95A3263-600x900.jpg 600w, https://styledumonde.com/wp-content/uploads/2021/07/Milan-SS21-day-1-by-STYLEDUMONDE-Street-Style-Fashion-Photography_95A3263-192x288.jpg 192w, https://styledumonde.com/wp-content/uploads/2021/07/Milan-SS21-day-1-by-STYLEDUMONDE-Street-Style-Fashion-Photography_95A3263-700x1050.jpg 700w, https://styledumonde.com/wp-content/uploads/2021/07/Milan-SS21-day-1-by-STYLEDUMONDE-Street-Style-Fashion-Photography_95A3263-768x1152.jpg 768w, https://styledumonde.com/wp-content/uploads/2021/07/Milan-SS21-day-1-by-STYLEDUMONDE-Street-Style-Fashion-Photography_95A3263-1024x1536.jpg 1024w, https://styledumonde.com/wp-content/uploads/2021/07/Milan-SS21-day-1-by-STYLEDUMONDE-Street-Style-Fashion-Photography_95A3263-1365x2048.jpg 1365w, https://styledumonde.com/wp-content/uploads/2021/07/Milan-SS21-day-1-by-STYLEDUMONDE-Street-Style-Fashion-Photography_95A3263.jpg 1400w" sizes="(max-width: 600px) 100vw, 600px">
srcset属性:
srcset="https://styledumonde.com/wp-content/uploads/2021/07/Milan-SS21-day-1-by-STYLEDUMONDE-Street-Style-Fashion-Photography_95A3263-600x900.jpg 600w, https://styledumonde.com/wp-content/uploads/2021/07/Milan-SS21-day-1-by-STYLEDUMONDE-Street-Style-Fashion-Photography_95A3263-192x288.jpg 192w, https://styledumonde.com/wp-content/uploads/2021/07/Milan-SS21-day-1-by-STYLEDUMONDE-Street-Style-Fashion-Photography_95A3263-700x1050.jpg 700w, https://styledumonde.com/wp-content/uploads/2021/07/Milan-SS21-day-1-by-STYLEDUMONDE-Street-Style-Fashion-Photography_95A3263-768x1152.jpg 768w, https://styledumonde.com/wp-content/uploads/2021/07/Milan-SS21-day-1-by-STYLEDUMONDE-Street-Style-Fashion-Photography_95A3263-1024x1536.jpg 1024w, https://styledumonde.com/wp-content/uploads/2021/07/Milan-SS21-day-1-by-STYLEDUMONDE-Street-Style-Fashion-Photography_95A3263-1365x2048.jpg 1365w, https://styledumonde.com/wp-content/uploads/2021/07/Milan-SS21-day-1-by-STYLEDUMONDE-Street-Style-Fashion-Photography_95A3263.jpg 1400w" sizes="(max-width: 600px) 100vw, 600px"
html = response.text #获取响应文本
ehtml = etree.HTML(html)  #将字符串转变成_Element对象
cover_url_list = ehtml.xpath("//a[@class='animsition-link']/div[@class='post-thumb']/img/@srcset") #定位并获取srcset内容格式
cover_url_list_max = []#最高像素封面图列表
            for cover_url in cover_url_list:
                cover_url = str(cover_url)
                cover_url = cover_url.split(', ')
                dic_temp = {}
                for url in cover_url:
                    url = url.split(' ')
                    dic_temp[url[0]] = int(url[1][:-1])
                url_temp = max(dic_temp, key=dic_temp.get)
                cover_url_list_max.append(url_temp)

600w

1400w

图片来自网络,版权归作者,如侵权联系我删除



所属网站分类: 技术文章 > 博客

作者:小飞刀你有点飘

链接:http://www.pythonpdf.com/blog/article/531/8b2a65c933fd9201c21e/

来源:编程知识网

任何形式的转载都请注明出处,如有侵权 一经发现 必将追究其法律责任

7 0
收藏该文
已收藏

评论内容:(最多支持255个字符)