截图
抓取《极客时间》iOS 手机客户端 api
。
# 专栏
my_column_url = "https://time.geekbang.org/serv/v1/my/columns"
# 视频专栏
video_url = "https://time.geekbang.org/serv/v1/column/articles"
# 音频专栏
audio_url = "https://time.geekbang.org/serv/v1/column/audios"
# 所有专栏
all_column_url = "https://time.geekbang.org/serv/v1/columns"
请求头
mobile_headers = {
'Host': "time.geekbang.org",
'X-GEEK-APP-NAME': "time",
'X-GEEK-DEVICE-MODEL': "iPhone7,2",
'Accept': "*/*",
'X-GEEK-OS-VER': "11.3",
'Ticket': "AwgBAQQEIBwAAAEEYkEQAAoEDwAAAAUEgMYTAAkBAQsCAwAHBLx.4K8GBF5ck0gCBOq6uFoDBOJ74lo-",
'X-GEEK-VER-NAME': "1.1.4",
'Device-Id': "3C9553DD-611C-4EBE-B703-109AD179F848",
'Device-Token': "c839237dbd40706072532646df282c50ac0b8ebf60cd06fa5e54d70b041b5c77",
'Accept-Language': "zh-cn",
'Accept-Encoding': "br, gzip, deflate",
'Content-Type': "application/json",
'Content-Length': "57",
'User-Agent': "iPhone7,2(iOS/11.3) GeekbangApp(Zeus/1.1.4) Weex/0.16.1 ExternalUA 750x1334",
'X-GEEK-OS-PLATFORM': "iOS",
'Referer': "http://www.geekbang.org/",
'X-GEEK-OS-NAME': "iOS",
'Connection': "keep-alive",
'Cache-Control': "no-cache"
}
获取 chrome
浏览器 cookie browsercookie
首先要从chrome
浏览器 登录http://geekbang.org
import browsercookie
# 获取 Chrome cookie
cj = browsercookie.chrome()
...
response = requests.request("POST", video_url, data=payload, cookies=cj, headers=mobile_headers)
...
最后就是解析 json
内容和下载文件了,详情参考源码:https://github.com/iOSDevLog/GeekTime
使用
-
python3
虚拟环境
(geektime) pip install -r requirements.txt
(geektime) python download_audio.py
(geektime) python download_audio_by_cid.py
login 'http://geekbang.org' from chrome first
...
id = 78 type = other column_title = 架构师
id = 50 type = audio column_title = 邱岳的产品手记
id = 77 type = video column_title = 9 小时搞定微信小程序开发
input audio column id
> 50
...
100%[===========================================================>] 1.87K --.-KB/s in 0s
...
...
...
(geektime) python download_video_by_cid.py
login 'http://geekbang.org' from chrome first
...
id = 78 type = other column_title = 架构师
id = 50 type = audio column_title = 邱岳的产品手记
id = 77 type = video column_title = 9 小时搞定微信小程序开发
input audio column id
> 77
...
第91讲___小程序之性能优化
{"hd":{"size":172783023,"url
libavutil 55. 78.100 / 55. 78.100
libavcodec 57.107.100 / 57.107.100
libavformat 57. 83.100 / 57. 83.100
libavdevice 57. 10.100 / 57. 10.100
libavfilter 6.107.100 / 6.107.100
libavresample 3. 7. 0 / 3. 7. 0
libswscale 4. 8.100 / 4. 8.100
libswresample 2. 9.100 / 2. 9.100
libpostproc 54. 7.100 / 54. 7.100
...