Skip to content

Commit 5350f2d

Browse files
committed
instagram crawler
0 parents  commit 5350f2d

File tree

4 files changed

+601
-0
lines changed

4 files changed

+601
-0
lines changed

README.md

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
### instagram 内容抓取
2+
3+
1、需要登录信息,即抓取时需要附带`cookie`,同时需要`user-agent`
4+
5+
2、数据获取接口及下载均有频率限制,无间隔的请求(几百个资源)会被限制,在被限制后睡眠一定时间继续。
6+
7+
3、内容抓取分为两个入口
8+
9+
* 一个是抓取某个用户发布的所有资源
10+
* 一个是抓取某个tag下的所有资源
11+
12+
两种入口附带的cookie不同,请求的URL不同。
13+
14+
4、抓取步骤:
15+
16+
1. 电脑端登陆ins,保存 `cookie``query_hash``user-agent`信息。后续所有请求附带`cookie``user-agent`
17+
2. 模拟请求个人主页/tag主页,通过解析HTML页面,得到userId/tag name。同时拿到第一页的数据及下页cursor。
18+
3. 通过API接口,根据`cursor`持续获取多页数据。所有数据获取完毕后开始下载。
19+
4. 返回的数据中,图片资源可以直接下载。视频资源需要再次请求视频地址获取接口获得视频地址,然后再下载。
20+
21+
5、请求数据接口:
22+
23+
user:
24+
25+
```
26+
https://www.instagram.com/graphql/query/?query_hash=a5164aed103f24b03e7b7747a2d94e3c&variables=%7B%22id%22%3A%22%s%22%2C%22first%22%3A${purePage}%2C%22after%22%3A%22%s%22%7D
27+
```
28+
tag:
29+
30+
```
31+
https://www.instagram.com/graphql/query/?query_hash=1780c1b186e2c37de9f7da95ce41bb67&variables=%7B%22tag_name%22%3A%22%s%22%2C%22first%22%3A${purePage}%2C%22after%22%3A%22%s%22%7D
32+
```
33+
34+
获取视频的地址:
35+
36+
```
37+
https://www.instagram.com/p/%s/?__a=1
38+
```
39+

0 commit comments

Comments
 (0)