代理池的,防止IP 被封
找到图片真实地址
现在看到的只是图片的预览地址 (previews)
1.检查:
2.鼠标变为箭头时查看网页源代码
关于怎样在源代码中找到图片的真实地址 ???
为什么在源代码界面 ctrl f 时候搜索的是 .png ???
首先图片地址是以 .jpg .png .jpeg 结尾
真实的图片地址是:
"contentUrl":"https://img3.wallspic.com/crops/0/5/0/6/7/176050/176050-old_paria_utah-paria-kanab-paria_river-towers_of_the_virgin-6319x4324.jpg"
用正则表达式匹配,只匹配高像素源图片
(r'contentUrl":"(https://img\d.wallspic.com/crops/.*?)"', response)
如果是下面的内容,则会连缩略图也匹配到
(r'"contentUrl":"(.*?)"',req)
import requests
import re
url = 'https://wallspic.com/cn/album/ji_shu/for_desktop'
response = requests.get(url = url).text
contentUrl = re.findall(r'contentUrl":"(https://img\d.wallspic.com/crops/.*?)"', response)
j = 0
for i in contentUrl:
j += 1
Content = requests.get(url = i).content
print(i)
with open(f'Wallspic-{j}.jpg', mode = 'wb') as f:
f.write(Content)
print(f'[+] 壁纸{j}保存完成!')
最终结果是以.jpg的形式输出的
也可以以 .png的形式输出,.png是益处多多
Desktop Wallpapers - Download HD Desktop Backgrounds
https://wall.alphacoders.com/by_sub_category.php?id=170792&name=Black+Wallpapers
下载的慢可能是网速的原因,需要;或者给 idea 配置代理,
刷新电脑本地的线路,保持畅通。
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
import requests
import re
def download_wallpapers(start_page, end_page):
for page in range(start_page, end_page+1):
url = f'https://wallspic.com/cn/album/dianying/popular?page={page}'
response = requests.get(url=url).text
contentUrl = re.findall(r'contentUrl":"(https://img\d.wallspic.com/crops/.*?)"', response)
j = 0
for i in contentUrl:
j += 1
Content = requests.get(url = i).content
print(i)
with open(f'p-{page}-{j}.jpg', mode = 'wb') as f:
f.write(Content)
print(f'[+] 壁纸{page}-{j}保存完成!')
# 下载第1页到第55页的壁纸
download_wallpapers(1, 55)
这段代码的作用是从wallspic.com网站下载电影壁纸,具体解读如下:
import requests
import re
def download_wallpapers(start_page, end_page):
for page in range(start_page, end_page+1):
url = f'https://wallspic.com/cn/album/dianying/popular?page={page}'
response = requests.get(url=url).text
contentUrl = re.findall(r'contentUrl":"(https://img\d.wallspic.com/crops/.*?)"', response)
for i in contentUrl:
Content = requests.get(url = i).content
with open(f'p-{page}-{j}.jpg', mode = 'wb') as f:
f.write(Content)
print(f'[+] 壁纸{page}-{j}保存完成!')