介绍NET牛人网站

脚本服务 (netnr.com)

提供大量的脚本服务1607224173238.png

练习破解 NET牛人的图片网站

最新壁纸 在线壁纸 NET牛人 (netnr.com)

1607224445189.png
url地址:

  1. https://ss.netnr.com/wallpaper

1.分析

打开一个页面,进行下拉,发现页面使用的是懒加载,发现了他的url

1607224556553.png
1607224645705.png

页面请求的地址为:

  1. 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

解码后:

  1. 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

参数解析

  1. url=http://wallpaper.apc.360.cn/index.php
  2. c=WallPaper
  3. start=25
  4. count=12
  5. from=360chrome
  6. a=getAppsByCategory
  7. cid=36

重要的参数:

  • start 请求的图片从第几张开始
  • count 需要返回多少组图片
  • cid id

问题:

  • cid如何获取

解决:

此页面访问地址:

  1. https://ss.netnr.com/wallpaper#36

发现36就是我们的cid

但是我们从哪里拿这个cid呢?

做过web开发的同学就会知道这样的id一定放在导航栏中的,方便页面的跳转

1607225020451.png

查看源码:

1607225034640.png

果然在这里

2.编写代码

2.1获取cid列表

  1. def getCidList():
  2. url = 'https://ss.netnr.com/wallpaper'
  3. html = requests.get(url=url, headers=headers).text
  4. tree = etree.HTML(html)
  5. name_list = tree.xpath('/html/body/div[2]/div[1]/div/div/a/text()')
  6. cid_list = tree.xpath('/html/body/div[2]/div[1]/div/div/a/@href')
  7. dic = dict(zip(name_list, cid_list))
  8. # 本地存储
  9. with open(path + '/cid.json', 'w', encoding='utf-8') as fp:
  10. json.dump(dic, fp=fp, ensure_ascii=False)

2.2获取cid列表

拿到json数据

  1. params = {
  2. 'url': 'http://wallpaper.apc.360.cn/index.php',
  3. 'c': 'WallPaper',
  4. 'start': start,
  5. 'count': count,
  6. 'from': '360chrome',
  7. 'a': 'getAppsByCategory',
  8. 'cid': cid
  9. }
  10. url = 'https://bird.ioliu.cn/v2'
  11. data = requests.get(url=url, params=params, headers=headers).json()
  12. data_list = data['data']

json

  1. {
  2. "id": "2037036",
  3. "class_id": "6",
  4. "resolution": "1920x1200",
  5. "url_mobile": "",
  6. "url": "http://p4.qhimg.com/bdr/__85/t019f2bf1d6ea85a7d6.jpg",
  7. "url_thumb": "http://p4.qhimg.com/bdr/__85/t019f2bf1d6ea85a7d6.jpg",
  8. "url_mid": "http://p4.qhimg.com/bdr/__85/t019f2bf1d6ea85a7d6.jpg",
  9. "download_times": "0",
  10. "imgcut": "0",
  11. "tag": "_全部_ _category_清纯_ _category_美肩_ _category_马尾_ _category_吊带_ _category_阳光_ _category_美女模特_",
  12. "create_time": "2020-12-02 20:14:58",
  13. "update_time": "2020-12-02 20:16:05",
  14. "ad_id": "",
  15. "ad_img": "",
  16. "ad_pos": "",
  17. "ad_url": "",
  18. "ext_1": "",
  19. "ext_2": "",
  20. "utag": "清纯 美肩 马尾 吊带 阳光",
  21. "tempdata": "",
  22. "rdata": [],
  23. "img_1600_900": "http://p4.qhimg.com/bdm/1600_900_85/t019f2bf1d6ea85a7d6.jpg",
  24. "img_1440_900": "http://p4.qhimg.com/bdm/1440_900_85/t019f2bf1d6ea85a7d6.jpg",
  25. "img_1366_768": "http://p4.qhimg.com/bdm/1366_768_85/t019f2bf1d6ea85a7d6.jpg",
  26. "img_1280_800": "http://p4.qhimg.com/bdm/1280_800_85/t019f2bf1d6ea85a7d6.jpg",
  27. "img_1280_1024": "http://p4.qhimg.com/bdm/1280_1024_85/t019f2bf1d6ea85a7d6.jpg",
  28. "img_1024_768": "http://p4.qhimg.com/bdm/1024_768_85/t019f2bf1d6ea85a7d6.jpg"
  29. }

完整代码

  1. import json
  2. import time
  3. import requests
  4. import os
  5. from lxml import etree
  6. from tqdm import tqdm
  7. headers = {
  8. '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'
  9. }
  10. # 保存位置
  11. path = './NET牛人图片'
  12. # 分辨率(默认最高)
  13. resolution = 'img_1600_900'
  14. def main():
  15. # 每次循环增加20
  16. # 1-20 i-(i+20)-1
  17. # 2
  18. j = 1
  19. for i in range(1, 4):
  20. print('爬取第%d张到第%d张的图片' % (j, (j + 20) - 1))
  21. download(6, '美女', j, (j + 20) - 1, resolution)
  22. j += 20
  23. print('线程睡眠1S')
  24. time.sleep(1)
  25. # cid_dic = readCidList()
  26. def download(cid, kind, start, count, resolution):
  27. if not os.path.exists(path + '/' + kind):
  28. os.mkdir(path + '/' + kind)
  29. params = {
  30. 'url': 'http://wallpaper.apc.360.cn/index.php',
  31. 'c': 'WallPaper',
  32. 'start': start,
  33. 'count': count,
  34. 'from': '360chrome',
  35. 'a': 'getAppsByCategory',
  36. 'cid': cid
  37. }
  38. url = 'https://bird.ioliu.cn/v2'
  39. data = requests.get(url=url, params=params, headers=headers).json()
  40. data_list = data['data']
  41. for item in tqdm(data_list):
  42. img_url = item[resolution]
  43. # img_name = str(item["utag"]).replace(' ','')
  44. # img_suffix = str(img_url).split('.')[-1]
  45. # file_name = img_name + '.' + img_suffix
  46. file_name = str(img_url).split('/')[-1]
  47. img_data = requests.get(img_url).content
  48. with open(path + '/' + kind + '/' + file_name, 'wb') as fp:
  49. fp.write(img_data)
  50. def readCidList():
  51. with open(path + '/cid.json', 'r', encoding='utf-8') as fp:
  52. data = json.load(fp)
  53. print(type(data))
  54. return data
  55. def getCidList():
  56. url = 'https://ss.netnr.com/wallpaper'
  57. html = requests.get(url=url, headers=headers).text
  58. tree = etree.HTML(html)
  59. name_list = tree.xpath('/html/body/div[2]/div[1]/div/div/a/text()')
  60. cid_list = tree.xpath('/html/body/div[2]/div[1]/div/div/a/@href')
  61. dic = dict(zip(name_list, cid_list))
  62. # 本地存储
  63. with open(path + '/cid.json', 'w', encoding='utf-8') as fp:
  64. json.dump(dic, fp=fp, ensure_ascii=False)
  65. # 创建文件夹
  66. def my_mkdir():
  67. if not os.path.exists(path):
  68. os.mkdir(path)
  69. if __name__ == '__main__':
  70. main()