-
Notifications
You must be signed in to change notification settings - Fork 40
/
Copy pathDouyinAccount.py
127 lines (106 loc) · 4.45 KB
/
DouyinAccount.py
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
import asyncio
import os.path
import sys
import time
import multiprocessing
from selenium.webdriver.common.by import By
import DouyinUtils
import Maintainace
import MyUtils
from retrying import retry
@retry(retry_on_exception=MyUtils.retry)
def main():
# 初`始`化``
users = DouyinUtils.allusers
allpieces = DouyinUtils.allpieces
readytodownload = DouyinUtils.readytodownload
# 变量
likecount = {}
ispic = []
Page = MyUtils.Chrome(mine=True)
page=Page.driver
while True:
# 登录
# region
page.get('https://www.douyin.com/user/MS4wLjABAAAAPw9P0loZpA5wjaWiHzxQb4B9E2Jgt4ZPWfiycyO_E4Q?showTab=like')
# MyUtils.skip([page, By.ID, "captcha-verify-image"])
# MyUtils.skip([page, By.ID, "login-pannel"])
# endregion
# 转到喜欢页面
# page.get(MyUtils.MyElement([page, By.XPATH, '//a[starts-with(@href,"//www.douyin.com/user/")]']).get_attribute('href'))
# time.sleep(1)
# DouyinUtils.HostPiecesLike([page])
# 下滚,保存url列表
MyUtils.scroll([page])
urllist = []
stole = MyUtils.nowstr()
for VideoElement in DouyinUtils.HostPieces([page]):
VideoUrl, VideoNum = DouyinUtils.piecetourlnum([VideoElement])
urllist.append(VideoUrl)
ispic.append(DouyinUtils.IsPic([VideoElement]))
MyUtils.delog('所有喜欢作品元素使用时间', MyUtils.counttime(stole))
# 逐一打开
for url in urllist:
stole = MyUtils.nowstr()
# 转到Video页面,没下过的第一遍进WebUserSpectrum
page.get(url)
# 跳过验证
MyUtils.skip([page, By.ID, "captcha-verify-image"])
e=Page.element('//*[@id="login-pannel"]/div[@class="dy-account-close"]',strict=False)
if not e==None:
Page.click(e)
# 变量
pic = ispic.pop(0)
VideoNum = MyUtils.tail(url, '/')
# 跳过下载过的
# if DouyinUtils.skiprecorded(VideoNum):
# continue
title = DouyinUtils.Title([page])
s = MyUtils.Element([page, By.XPATH, '/html/head/meta[3]']).get_attribute('content')
userid = s[s.rfind(' - ') + 3:s.rfind('发布在抖音,已经收获了') - 9]
if DouyinUtils.skipdownloaded(pic, allpieces, VideoNum, title, userid):
# 取消喜欢
DouyinUtils.dislike([page])
MyUtils.delog('已取消喜欢')
continue
path = '../抖音/' + userid
# 添加下载
DouyinUtils.load(pic, page, VideoNum, userid, title, DouyinUtils.readytodownload)
# 跳过直播
try:
l1 = MyUtils.Elements([page, By.XPATH, '/html/body/div[1]/div/div[2]/div/div/div[2]/div/div[1]/div[1]/a'], depth=9, silent=True)
l2 = MyUtils.Elements([page, By.XPATH, '/html/body/div[1]/div[1]/div[2]/div/main/div[2]/div[1]/div[1]/a'], depth=9, silent=True)
userurl = MyUtils.extend(l1, l2)[0].get_attribute('href')
except Exception as e:
MyUtils.delog([l1, l2])
MyUtils.warn(e)
time.sleep(999)
if userurl.rfind('live') > 0:
continue
# 获取UserUID
ueruid = userurl[userurl.rfind('/') + 1:]
MyUtils.delog(ueruid)
# 取消喜欢
DouyinUtils.dislike([page])
MyUtils.delog('已取消喜欢')
# # 跳过UserUID已经记录的
if (ueruid in list(users.d.keys())):
MyUtils.delog('已在用户列表中')
continue
# 查看是否需要记录UserUID,出现重复超过1次的用户即记录
if likecount.get(ueruid) == None:
likecount.update({ueruid: 1})
MyUtils.log('新用户')
else:
likecount.update({ueruid: likecount.get(ueruid) + 1})
MyUtils.log('出现过的的用户')
if likecount.get(ueruid) > 1:
likecount.update({ueruid: -111})
MyUtils.log('记录了新用户')
DouyinUtils.addauthor(ueruid, userid, users)
MyUtils.log(f'上个作品添加下载耗时{MyUtils.counttime(stole)}')
MyUtils.delog(likecount)
# 结束
pass
if __name__ == '__main__':
main()