下面代码是在图片网站上截取的,想问下用Python爬虫,怎样才能过滤出images下不同size的图片url呢?最好能给出关键的代码
.........这里省略了部分代码..........
"images": [{
"size": "watermark",
"url": "https:\/\/drscdn.500px.org\/photo\/original\/store\/67585293\/m%3D900_k%3D2_b%3D2_dpi%3D300_attachment%3D1_tags%3D1\/e47f93b520c772b2612bef1ff2fa77ae"
},
{
"size": "280",
"url": "https:\/\/drscdn.500px.org\/photo\/67585293\/w%3D280_s%3D1\/a967861eaf97496c9243c9aaccb63502"
},
{
"size": "560",
"url": "https:\/\/drscdn.500px.org\/photo\/67585293\/w%3D560_s%3D1\/90e4feec7585c24a5f1d45b1ee21262b"
},
{
"size": "600",
"url": "https:\/\/drscdn.500px.org\/photo\/67585293\/w%3D600_s%3D1\/aa4e4a084ea37fa1ce8a82c3865ce43a"
},
{
"size": "115",
"url": "https:\/\/drscdn.500px.org\/photo\/67585293\/w%3D115_h%3D115_s%3D1\/8fae531a821e375dda4f4938b0b5829f"
},
{
"size": "160",
"url": "https:\/\/drscdn.500px.org\/photo\/67585293\/w%3D160_h%3D160_s%3D1\/0e4a9829237dd66700a27ebed6d8f761"
},
{
"size": "2048",
"url": "https:\/\/drscdn.500px.org\/photo\/67585293\/w%3D2048\/d8142c223fa99fc99b9bd4a1b44462eb"
}],
.........这里省略了部分代码..........
那些斜杠是正则转义符,后面的%3D什么的也是URL地址转义。
所以你直接用正则读取一次,再转义地址就行了。
Python我不清楚怎么写,我只知道第二次转义用Javascript的话是decodeURIComponent(str)就可以了。你自己百度一下就行了。
另外,别上来就要别人给你代码,作为一个写code的,要自己动手去找找原因或者解决方案。