鍍金池/ 問答/Python/ 圖片可以下載,但是爬的鏈接進去卻不是這張圖

圖片可以下載,但是爬的鏈接進去卻不是這張圖

試著爬一個網(wǎng)站,里面的圖片可以右擊下載,但是看里面的鏈接卻不是該圖片。
網(wǎng)站鏈接:http://www.plantphoto.cn/tu/2...。
請教下高手,這是后臺有什么技術(shù)隱藏了真正的圖片鏈接了么?該如何獲得真正的鏈接。謝謝!

回答
編輯回答
疚幼

網(wǎng)站做了防盜鏈措施 ,請求的時候在請求頭里加上referer就可以了。
demo代碼如下:

#! /usr/bin/env python
# -*- coding: utf-8 -*-
""" 
@author:hp 
@file: 6.5.py 
@time: 2018/6/5
"""
import requests,os

def download_picture():

    url = 'http://img.plantphoto.cn/image2/b/2391908.jpg'
    header = {'Referer': 'http://www.plantphoto.cn/tu/2391908'}
    res = requests.get(url,headers=header,stream=True)
    with open(os.getcwd() + os.sep + '2391908.jpg',mode= 'wb') as f:
            f.write(res.content)

if __name__ == '__main__':
    download_picture()

圖片描述

2017年4月14日 14:42