python - 怎么查看网址做的是什么反爬虫
ringa_lee
ringa_lee 2017-06-12 09:27:51
0
4
1286

网址:https://www.nvshens.com/g/22377/,该网站直接游览器打开然后,点击图片右键是可以下载的,然后我爬虫直接请求下来的图片就已经被屏蔽了,然后我改了headers跟设置了ip代理,还是没用。但抓包来看也不是动态加载的数据呀!!!求解答= =

ringa_lee
ringa_lee

ringa_lee

全部回复(4)
过去多啦不再A梦

妹子挺漂亮的哈。
右键确实能打开,但是刷新一下就成盗链图片了。一般防盗链,服务器端是会检查请求头里面的Referer字段,这就是为什么刷新后就不是原图的原因(刷新后Referer变了)。

img_url = "https://t1.onvshen.com:85/gallery/21501/22377/s/003.jpg"
r = requests.get(img_url, headers={'Referer':"https://www.nvshens.com/g/22377/"}).content
with open("00.jpg",'wb') as f:
    f.write(r)
学霸

获取图片时抓包看漏什么参数没。

我想大声告诉你

光顾着看网站内容,差点忘记了正式了。
你可以把你请求的信息全部按照

然后在试试

女神的闺蜜爱上我

Referer 照这网站的设计应该是各别的页面会比较符合假装是人的行为,而并不是用单一的Referer
以下是完整能跑的代码,抓18页所有的图片

# Putting all together
def url_guess_src_large (u):
    return ("https://www.nvshens.com/img.html?img=" +  '/'.join(u.split('/s/')))
# 下载函数
def get_img_using_requests(url, fn ):
    import shutil
    headers ['Referer'] = url_guess_src_large(url) #"https://www.nvshens.com/g/22377/" 
    print (headers)
    response = requests.get(url, headers = headers, stream=True)
    with open(fn, 'wb') as out_file:
        shutil.copyfileobj(response.raw, out_file)
    del response

import requests
# 用xpath擷取內容
from lxml import etree
url_ = 'https://www.nvshens.com/g/22377/{p}.html'  
headers = {
    "Connection" : "close",  # one way to cover tracks
    "User-Agent" : "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2900.1 Iron Safari/537.36}"
}

for i in range(1,18+1):
    url = url_.format(p=i)
    r = requests.get(url, headers=headers)
    html = requests.get(url,headers=headers).content.decode('utf-8')
    selector = etree.HTML(html)
    xpaths = '//*[@id="hgallery"]/img/@src'
    content = [x for x in selector.xpath(item)]
    urls_2get = [url_guess_src_large(x) for x in content]
    filenames = [os.path.split(x)[0].split('/gallery/')[1].replace("/","_") + "_" + os.path.split(x)[1] for x in urls_2get]
    for i, x in enumerate(content):
        get_img_using_requests (content[i], filenames[i])
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板