msdn.itellyou.cn这个网站首页是SPA单页应用,所有数据用过请求restfulAPI来获取,然后动态生成页面。
通过chrome的调试工具可以抓取到获取数据的API接口地址,以及参数情况。

get_download_list函数中传入的id是在首页操作系统页面抓到的。

下面脚本是抓取操作系统的下载链接

#!/usr/bin/python
# -*- coding: utf-8 -*-
import re
import json
import requestsAPI_MSDN_INDEX = 'https://msdn.itellyou.cn/'API_INDEX = 'http://msdn.itellyou.cn/Category/Index'API_GET_LANG = 'https://msdn.itellyou.cn/Category/GetLang'API_GET_LIST = 'https://msdn.itellyou.cn/Category/GetList'API_GET_PRODUCT = 'https://msdn.itellyou.cn/Category/GetProduct'headers = {
'Referer':'https://msdn.itellyou.cn/'
}RESULT = {'data':[]}
def get_product(id):r = requests.post(API_GET_PRODUCT, headers=headers, data={'id':id})if r.status_code == requests.codes.ok:item = r.json().get('result')print 'FileName:%s' % item.get('FileName')print 'PostData:%s' % item.get('PostDateString')print 'SHA1:%s' % item.get('SHA1')print 'size:%s' % item.get('size')print 'Download:%s' % item.get('DownLoad')return itemdef get_list(id, lang_id):r = requests.post(API_GET_LIST, headers=headers, data={'id':id, 'lang':lang_id, 'filter':'true'})if r.status_code == requests.codes.ok:product_list = []for item in r.json().get('result'):product_info = get_product(item.get('id'))product_list.append(product_info)return product_listdef get_lang(id):r = requests.post(API_GET_LANG, headers=headers, data={'id':id})if r.status_code == requests.codes.ok:lang_list = []for lang in r.json().get('result'):print lang.get('lang')info = {'lang':lang.get('lang'), 'product_list':get_list(id,lang.get('id'))}lang_list.append(info)return lang_listdef get_download_list(category_id):r = requests.post(API_INDEX, headers=headers, data={'id':category_id})if r.status_code == requests.codes.ok:for item in r.json():print 'System Name: %s'% item.get('name')system_info = get_lang(item.get('id'))system_info = {'name':item.get('name'), 'lang_list':system_info}RESULT['data'].append(system_info)print 'finishied!!!'return RESULTif __name__ == '__main__':json_buffer = get_download_list('7ab5f0cb-7607-4bbe-9e88-50716dc43de6')with open('./msdn.json','w') as f:json.dump(json_buffer,f)

抓取效果

抓取所有操作系统的下载链接后,保存在本地msdn.json,现在把这些操作系统的文件,自动离线下载到百度云网盘里面。
通过chrome浏览器的开发人员调试工具,可以抓到百度云创建目录以及离线下载这两个功能的xhr请求,我们可以构造一下请求,然后读取保存的json文件,实现自动离线下载

import requests,jsonheaders = {
'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.81 Safari/537.36',
'Accept': 'application/json, text/javascript, */*; q=0.01',
'Cookie': '这里改成你的cookie',
'Referer':'https://pan.baidu.com/disk/home?'
}def download(source_url, path):host = 'https://pan.baidu.com/rest/2.0/services/cloud_dl?channel=chunlei&web=1&app_id=250528&bdstoken=a1ca97d6f5763c08df76e5497c66c936&logid=MTUzNjg4NzA3MjI2MjAuNzIxMTE4MDY2NDI0NDg1Ng==&clienttype=0'payload = {'method': 'add_task','app_id': '250528','source_url': source_url,'save_path': path,'type': '3'}r = requests.post(host, headers = headers, data = payload)if r.status_code == requests.codes.ok:if r.json().get('status') == 0:return Truereturn Falsedef create(path):host = 'https://pan.baidu.com/api/create?a=commit&channel=chunlei&web=1&app_id=250528&bdstoken=a1ca97d6f5763c08df76e5497c66c936&logid=MTUzNjg4NzMyODE2MzAuMTU4NTI4OTI3NDUxNDY1ODU=&clienttype=0'payload = {'path': path,'isdir': '1','block_list': '[]',}r = requests.post(host, headers = headers, data = payload)if r.status_code == requests.codes.ok:if r.json().get('status') == 0:return pathreturn Falsedef main():with open('./msdn.json','r') as f:temp = json.loads(f.read())['data']for system in temp:for lang in system['lang_list']:tree_folder = '/msdn_itellyou/%s/%s' % (system['name'],lang['lang'])if create(tree_folder):print 'Create folder %s success!!'% tree_folderfor product in lang['product_list']:if product and download(product['DownLoad'], tree_folder):print 'Download ISO %s success!!' % product['FileName']if __name__ == '__main__':main()

由于百度云的离线下载功能有验证,频繁调用离线下载的API会让你输入验证码。到此不再深入。

【爬虫】抓取msdn.itellyou.cn所有操作系统镜像下载链接相关推荐

  1. Python爬虫:利用JS逆向抓取携程网景点评论区图片的下载链接

    Python爬虫:利用JS逆向抓取携程网景点评论区图片的下载链接 1. 前言 2. 实现过程 3. 运行结果 1. 前言 文章内容可能存在版权问题,为此,小编不提供相关实现代码,只是从js逆向说一说到 ...

  2. python爬取百度贴吧中的所有邮箱_使用 Python 编写多线程爬虫抓取百度贴吧邮箱与手机号...

    原标题:使用 Python 编写多线程爬虫抓取百度贴吧邮箱与手机号 不知道大家过年都是怎么过的,反正栏主是在家睡了一天,醒来的时候登QQ发现有人找我要一份贴吧爬虫的源代码,想起之前练手的时候写过一个抓 ...

  3. php实现爬虫抓取法定节假日放假和补班安排数据

    今天闲聊群有朋友问我怎么判断今天是不是法定节假日,是上班还是放假还是假期补班,想了想应该有相应的api,直接去调用就行了,但也可以去国务院官网发的放假通知上面去抓取,今天就跟大家分享下php实现爬虫抓 ...

  4. Python判断股票是交易日,爬虫抓取深交所交易日历

    为了判断某一天是不是股票的交易日,以此区分自然日与交易日,我们通过抓取深交所的交易日历获取相关数据 获取交易日思路 首先,打开深交所的交易日历页面:http://www.szse.cn/aboutus ...

  5. python 爬虫抓取某电商页面的商品价格

    1. 业务需求 最近想通过爬虫抓取某电商商品页的商品详情, 浏览器页面打开如下: 本来以为是一个很简单的爬虫,却没想到一波三折,并没有那么简单. 2. 付诸实践 接到任务后,就兴冲冲的写了段代码来爬取 ...

  6. 基于Thinkphp5+phpQuery 网络爬虫抓取数据接口,统一输出接口数据api

    TP5_Splider 一个基于Thinkphp5+phpQuery 网络爬虫抓取数据接口 统一输出接口数据api.适合正在学习Vue,AngularJs框架学习 开发demo,需要接口并保证接口不跨 ...

  7. C#网页爬虫抓取行政区划

    借鉴C#网页爬虫抓取行政区划,从国家统计局获取了最新行政区域数据. 以下为代码贴片: 数据库类: public class City {public decimal ID { get; set; }p ...

  8. Python网络爬虫抓取彩票排列3全部历史数据

    之前学了福彩3D网络爬虫技术,然后我研究了一天时间,写了一个体彩排列3爬虫抓取程序,为了感谢网友们的贡献,我决定分享代码 首先找一家比较大型的网站,500彩票网,因为是美国上市公司,轻易不会黄,这样写 ...

  9. python 爬虫抓取心得分享

    /** author: insun title:python 爬虫抓取心得分享 blog:http://yxmhero1989.blog.163.com/blog/static/11215795620 ...

  10. 爬虫抓取页面数据原理(php爬虫框架有很多 )

    爬虫抓取页面数据原理(php爬虫框架有很多 ) 一.总结 1.php爬虫框架有很多,包括很多傻瓜式的软件 2.照以前写过java爬虫的例子来看,真的非常简单,就是一个获取网页数据的类或者方法(这里的话 ...

最新文章

  1. mysql参数文件选项组_my.cnf文件关于组选项的总结
  2. jsonarray和jsonObject的转化
  3. C# Process执行bat
  4. spring boot二:搭建环境
  5. 数据中心迎来重大利好消息,工商业电价降低10%
  6. protobuf java_ProtoBuf for java使用笔记 | 学步园
  7. 【论文解读】突破置换模块计算瓶颈,MSRA开源轻量版HRNet,超越主流轻量化网络!|CVPR2021...
  8. cuda的shared momery
  9. 《大道至简》第二篇读后感
  10. Linux查看CPU型号及内存频率及其它信息的命令
  11. iOS开发多线程篇---线程间的通信
  12. 什么是自媒体知识付费
  13. 计算机专业书读后感300字,读一本书读后感300字(精选9篇)
  14. AppCan TreeView
  15. python_判断是否回文
  16. asp连接excel数据库
  17. unity 控制对象移动、旋转
  18. 25个能够激发灵感的暗色调CSS Web设计欣赏
  19. MySQL 中的 INSERT 是怎么加锁的?(荣耀典藏版)
  20. 小米笔记本Pro15.6蓝屏(0x00000124)——重装系统,拆机清灰加固态

热门文章

  1. python数据结构题目_python数据结构_递归python数据结构_python数据结构 面试题 - 云+社区 - 腾讯云...
  2. LINK : fatal error LNK1561和LINK : fatal error LNK1168:解决方法
  3. 老板要我开发一个OA多级审批流(干货满满)
  4. html5 边框效果图,图片边框border-image的用法
  5. MATLAB期末复习
  6. 2022阿里巴巴云栖大会
  7. 标准差SD、相对标准偏差RSD学习和python实现
  8. 经典情歌Lionel Richie李昂纳尔·里奇 - hello -say you say me
  9. 网传的南方某科技大学最新研究成果
  10. 虚拟机VirtualBox下载与安装、安装Ubuntu超详细图文步骤,对一些配置问题也有所写。