发布于2021-07-25 06:35 阅读(825) 评论(0) 点赞(7) 收藏(0)
例如:
<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/
来源:编程知识网
任何形式的转载都请注明出处,如有侵权 一经发现 必将追究其法律责任
昵称:
评论内容:(最多支持255个字符)
投诉与举报,广告合作请联系vgs_info@163.com或QQ3083709327
免责声明:网站文章均由用户上传,仅供读者学习交流使用,禁止用做商业用途。若文章涉及色情,反动,侵权等违法信息,请向我们举报,一经核实我们会立即删除!