介绍NET牛人网站
提供大量的脚本服务
练习破解 NET牛人的图片网站

url地址:
https://ss.netnr.com/wallpaper
1.分析
打开一个页面,进行下拉,发现页面使用的是懒加载,发现了他的url


页面请求的地址为:
https://bird.ioliu.cn/v2?url=http%3A%2F%2Fwallpaper.apc.360.cn%2Findex.php%3Fc%3DWallPaper%26start%3D25%26count%3D12%26from%3D360chrome%26a%3DgetAppsByCategory%26cid%3D36
解码后:
https://bird.ioliu.cn/v2?url=http://wallpaper.apc.360.cn/index.php?c=WallPaper&start=25&count=12&from=360chrome&a=getAppsByCategory&cid=36
参数解析
url=http://wallpaper.apc.360.cn/index.phpc=WallPaperstart=25count=12from=360chromea=getAppsByCategorycid=36
重要的参数:
- start 请求的图片从第几张开始
- count 需要返回多少组图片
- cid id
问题:
- cid如何获取
解决:
此页面访问地址:
https://ss.netnr.com/wallpaper#36
发现36就是我们的cid
但是我们从哪里拿这个cid呢?
做过web开发的同学就会知道这样的id一定放在导航栏中的,方便页面的跳转
查看源码:

果然在这里
2.编写代码
2.1获取cid列表
def getCidList():url = 'https://ss.netnr.com/wallpaper'html = requests.get(url=url, headers=headers).texttree = etree.HTML(html)name_list = tree.xpath('/html/body/div[2]/div[1]/div/div/a/text()')cid_list = tree.xpath('/html/body/div[2]/div[1]/div/div/a/@href')dic = dict(zip(name_list, cid_list))# 本地存储with open(path + '/cid.json', 'w', encoding='utf-8') as fp:json.dump(dic, fp=fp, ensure_ascii=False)
2.2获取cid列表
拿到json数据
params = {'url': 'http://wallpaper.apc.360.cn/index.php','c': 'WallPaper','start': start,'count': count,'from': '360chrome','a': 'getAppsByCategory','cid': cid}url = 'https://bird.ioliu.cn/v2'data = requests.get(url=url, params=params, headers=headers).json()data_list = data['data']
json
{"id": "2037036","class_id": "6","resolution": "1920x1200","url_mobile": "","url": "http://p4.qhimg.com/bdr/__85/t019f2bf1d6ea85a7d6.jpg","url_thumb": "http://p4.qhimg.com/bdr/__85/t019f2bf1d6ea85a7d6.jpg","url_mid": "http://p4.qhimg.com/bdr/__85/t019f2bf1d6ea85a7d6.jpg","download_times": "0","imgcut": "0","tag": "_全部_ _category_清纯_ _category_美肩_ _category_马尾_ _category_吊带_ _category_阳光_ _category_美女模特_","create_time": "2020-12-02 20:14:58","update_time": "2020-12-02 20:16:05","ad_id": "","ad_img": "","ad_pos": "","ad_url": "","ext_1": "","ext_2": "","utag": "清纯 美肩 马尾 吊带 阳光","tempdata": "","rdata": [],"img_1600_900": "http://p4.qhimg.com/bdm/1600_900_85/t019f2bf1d6ea85a7d6.jpg","img_1440_900": "http://p4.qhimg.com/bdm/1440_900_85/t019f2bf1d6ea85a7d6.jpg","img_1366_768": "http://p4.qhimg.com/bdm/1366_768_85/t019f2bf1d6ea85a7d6.jpg","img_1280_800": "http://p4.qhimg.com/bdm/1280_800_85/t019f2bf1d6ea85a7d6.jpg","img_1280_1024": "http://p4.qhimg.com/bdm/1280_1024_85/t019f2bf1d6ea85a7d6.jpg","img_1024_768": "http://p4.qhimg.com/bdm/1024_768_85/t019f2bf1d6ea85a7d6.jpg"}
完整代码
import jsonimport timeimport requestsimport osfrom lxml import etreefrom tqdm import tqdmheaders = {'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.67 Safari/537.36 Edg/87.0.664.52'}# 保存位置path = './NET牛人图片'# 分辨率(默认最高)resolution = 'img_1600_900'def main():# 每次循环增加20# 1-20 i-(i+20)-1# 2j = 1for i in range(1, 4):print('爬取第%d张到第%d张的图片' % (j, (j + 20) - 1))download(6, '美女', j, (j + 20) - 1, resolution)j += 20print('线程睡眠1S')time.sleep(1)# cid_dic = readCidList()def download(cid, kind, start, count, resolution):if not os.path.exists(path + '/' + kind):os.mkdir(path + '/' + kind)params = {'url': 'http://wallpaper.apc.360.cn/index.php','c': 'WallPaper','start': start,'count': count,'from': '360chrome','a': 'getAppsByCategory','cid': cid}url = 'https://bird.ioliu.cn/v2'data = requests.get(url=url, params=params, headers=headers).json()data_list = data['data']for item in tqdm(data_list):img_url = item[resolution]# img_name = str(item["utag"]).replace(' ','')# img_suffix = str(img_url).split('.')[-1]# file_name = img_name + '.' + img_suffixfile_name = str(img_url).split('/')[-1]img_data = requests.get(img_url).contentwith open(path + '/' + kind + '/' + file_name, 'wb') as fp:fp.write(img_data)def readCidList():with open(path + '/cid.json', 'r', encoding='utf-8') as fp:data = json.load(fp)print(type(data))return datadef getCidList():url = 'https://ss.netnr.com/wallpaper'html = requests.get(url=url, headers=headers).texttree = etree.HTML(html)name_list = tree.xpath('/html/body/div[2]/div[1]/div/div/a/text()')cid_list = tree.xpath('/html/body/div[2]/div[1]/div/div/a/@href')dic = dict(zip(name_list, cid_list))# 本地存储with open(path + '/cid.json', 'w', encoding='utf-8') as fp:json.dump(dic, fp=fp, ensure_ascii=False)# 创建文件夹def my_mkdir():if not os.path.exists(path):os.mkdir(path)if __name__ == '__main__':main()

