-
Notifications
You must be signed in to change notification settings - Fork 5
/
douyin
53 lines (50 loc) · 1.78 KB
/
douyin
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#coding:utf-8
import requests
import json
import csv
import time
# 去重后的id列表
uidList=[['73888615414']]
# 所有信息
allList=[]
# 跑过的uid列表
runList=[]
payload={'aid':'1128','count':'5000','max_time':'1533104541633','user_id':'81744784362'}
followerUrl= 'https://aweme.snssdk.com/aweme/v1/user/follower/list/'
followingUrl='https://aweme.snssdk.com/aweme/v1/user/following/list/'
headers={'user-agent': 'Aweme/1.8.0 (iPhone; iOS 11.2.2; Scale/3.00)'}
# 模拟请求一下,看看结果
r = requests.get(followingUrl, headers=headers,params=payload)
r.encoding='utf-8'
jr=json.loads(r.text)
def getList(uidList):
if(len(uidList)>=9000):
print('9000了..退出递归')
return False
for uid in uidList:
if(uid[0] not in runList):
if(len(uidList)>=9000):
return
payload['user_id']=str(uid[0])
runList.append(uid[0])
r = requests.get(followerUrl, headers=headers, params=payload)
r.encoding = 'utf-8'
j = json.loads(r.text)['followers']
print('当前uid总数:', len(uidList),'当前用来跑的uid:',uid, 'uid列表:',uidList)
time.sleep(1)
for item in j:
if (len(uidList) >= 9000):
return
if([item['uid']] not in uidList):
uidList.append([item['uid']])
allList.append(item)
getList(uidList)
getList(uidList)
print(len(uidList),uidList)
with open('userList1.csv','w',newline='',encoding='utf-8-sig') as csvfile:
writer=csv.writer(csvfile)
print('正在写入csv')
writer.writerow(['uid'])
for i in uidList:
writer.writerow((i))
print(r.encoding,allList)