Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit ab71d1c

Browse files
committed
乱七八糟的Bug修复
1 parent 179a947 commit ab71d1c

File tree

9 files changed

+533
-175
lines changed

9 files changed

+533
-175
lines changed

adb微信加好友/config.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
[default]
2-
phone_file_path = C:\Users\lenovo\PycharmProjects\leetcode-python-\樊登读书脚本\phone_number.xls
2+
phone_file_path = C:\Users\lenovo\PycharmProjects\leetcode-python-\adb微信加好友\phone_number.xls

adb微信加好友/data/dump.xml

Lines changed: 404 additions & 107 deletions
Large diffs are not rendered by default.

adb微信加好友/main.py

Lines changed: 106 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
phoe_tables = phone_excel.sheet_by_index(0)
2727
phone_get_col = 1 # 读取手机号的列
2828
phone_write_col = 2 # 写入手机号的列
29-
wait_time = 20 # 等待间隔
29+
wait_time = 40 # 等待间隔
3030
phone_can_write_index = 1 # 从哪一行开始记录手机号
3131

3232

@@ -99,8 +99,8 @@ def __init__(self, port=None, device=None):
9999
self._device = device # 设备号
100100
self._p = '' if (port is None) else '-P ' + str(port) + ' '
101101
self._s = '' if (device is None) else '-s ' + str(device) + ' '
102-
self._baseShell = adb_path() + 'adb ' + self._p + self._s # 指定端口 指定设备 组装adb命令
103102
self._basePath = os.path.dirname(__file__) # 获取该文件(adbtools.py) 所在对文件夹路径
103+
self._baseShell = adb_path() + 'adb ' + self._p + self._s # 指定端口 指定设备 组装adb命令
104104
self._nodes = None # 缓存当前查找到的nodes => type 列表 | value 字典
105105
self._x = None
106106
self._y = None
@@ -138,7 +138,6 @@ def swipe(self, start=None, end=None):
138138
end = x1, y1 - int(y1 / 2)
139139
x2, y2 = end
140140
cmd = self._baseShell + "shell input swipe " + str(x1) + " " + str(y1) + " " + str(x2) + " " + str(y2)
141-
print(cmd)
142141
os.system(cmd)
143142

144143
def show_current_pk(self):
@@ -165,8 +164,11 @@ def check_screen(self):
165164
:return:
166165
"""
167166
# print(self._basePath)
167+
168+
# os.system(self._baseShell+"shell dumpsys window policy | findstr mScreenOnFully")
169+
168170
displayPowerState = os.popen(
169-
"adb shell dumpsys window policy | findstr mScreenOnFully ").read().strip() # 读出来这种 mAwake=truemScreenOnEarly=true mScreenOnFully=true 字节类型
171+
" bash shell dumpsys window policy | findstr mScreenOnFully ").read().strip() # 读出来这种 mAwake=truemScreenOnEarly=true mScreenOnFully=true 字节类型
170172
# print("134",displayPowerState)
171173
state = str(displayPowerState).split(" ")[1].split("=")[1]
172174
if state == 'true':
@@ -187,12 +189,20 @@ def check_screen_lock(self):
187189
:return:
188190
"""
189191
displayPowerState = os.popen(
190-
'adb shell dumpsys window policy |findstr isStatusBarKeyguard').read().strip() # 读出来这种 mAwake=truemScreenOnEarly=true mScreenOnFully=true 字节类型
192+
self._baseShell + 'shell dumpsys window policy |findstr isStatusBarKeyguard').read().strip() # 读出来这种 mAwake=truemScreenOnEarly=true mScreenOnFully=true 字节类型
191193
state = str(displayPowerState).split(" ")[-1].split("=")[-1]
192194
if state == 'true':
193195
return True
194196
return False
195197

198+
def return_home(self):
199+
"""
200+
返回桌面
201+
:return:
202+
"""
203+
self.adb_keyboard(3)
204+
205+
196206
def unlock(self):
197207
"""
198208
解锁 82 已解锁则跳过
@@ -261,6 +271,7 @@ def generate_nodes(self):
261271
解析xml文件生成node数据
262272
:return:
263273
"""
274+
# print("file_path",self._basePath + '/data/dump.xml')
264275
xml = xmlParser.ElementTree(file=self._basePath + '/data/dump.xml')
265276
nodes = xml.findall(path=".//node") # 全部node节点
266277
tem_node = []
@@ -400,17 +411,23 @@ def click_add_friend(self):
400411
self.click_by_id_after_refresh("com.tencent.mm:id/rb")
401412
except Exception:
402413
pass
403-
self.click_by_text_after_refresh("添加朋友")
414+
try:
415+
self.click_by_text_after_refresh("添加朋友")
416+
except Exception:
417+
pass
404418

405419
def click_wechat_and_friend(self):
406420
"""
407421
点击那两个 微信号/手机号
408422
:return:
409423
"""
410-
bounds1 = self.find_node_by_resource_id("com.tencent.mm:id/dlc")
411-
self.click_use_bounds(bounds1)
412-
bounds2 = self.find_node_by_resource_id("com.tencent.mm:id/c4j")
413-
self.click_use_bounds(bounds2)
424+
try:
425+
bounds1 = self.find_node_by_resource_id("com.tencent.mm:id/dlc")
426+
self.click_use_bounds(bounds1)
427+
bounds2 = self.find_node_by_resource_id("com.tencent.mm:id/c4j")
428+
self.click_use_bounds(bounds2)
429+
except Exception:
430+
pass
414431

415432
def click_use_bounds(self, bounds):
416433
x, y = self.cal_coordinate(bounds)
@@ -536,62 +553,67 @@ def clean_phone(self):
536553
return False
537554

538555
def add_friends(self, phone):
556+
try:
557+
self._adb.return_home()
558+
print("返回桌面")
559+
self._adb.start_wechat()
560+
print("启动微信")
561+
phone = str(int(phone))
562+
print("当前手机号:{}".format(phone))
563+
self._adb.adb_input(phone)
564+
# 点击搜索
565+
search_res = "搜索:" + phone
566+
self._adb.click_by_text_after_refresh(search_res)
567+
print(' ==> 点击搜索 ==> ')
568+
569+
if self._adb.find_node_by_text('该用户不存在') or self._adb.find_node_by_text('被搜帐号状态异常,无法显示'):
570+
print(' <== 该用户不存在 或 帐号异常 <== ')
571+
write_to_excel(phone_file_path, phone_can_write_index, phone_write_col, "该用户不存在")
572+
573+
# 查找成功
574+
elif self._adb.find_node_by_text('添加到通讯录'):
575+
576+
# self._adb.click(0)
577+
self._adb.click_by_text_after_refresh('添加到通讯录')
578+
579+
if self._adb.find_node_by_text('发消息'):
580+
print(' <== 发送成功 <== ')
581+
write_to_excel(phone_file_path, phone_can_write_index, phone_write_col, " 发送成功 ")
582+
self._adb.adb_put_back()
583+
else:
584+
self._adb.click_by_text_after_refresh("发送")
539585

540-
phone = str(int(phone))
541-
print("当前手机号:{}".format(phone))
542-
self._adb.adb_input(phone)
543-
# 点击搜索
544-
545-
search_res = "搜索:" + phone
546-
self._adb.click_by_text_after_refresh(search_res)
547-
print(' ==> 点击搜索 ==> ')
548-
549-
if self._adb.find_node_by_text('该用户不存在') or self._adb.find_node_by_text('被搜帐号状态异常,无法显示'):
550-
print(' <== 该用户不存在 或 帐号异常 <== ')
551-
write_to_excel(phone_file_path, phone_can_write_index, phone_write_col, "该用户不存在")
552-
553-
# 查找成功
554-
elif self._adb.find_node_by_text('添加到通讯录'):
555-
556-
# self._adb.click(0)
557-
self._adb.click_by_text_after_refresh('添加到通讯录')
558-
559-
if self._adb.find_node_by_text('发消息'):
560-
print(' <== 发送成功 <== ')
561-
write_to_excel(phone_file_path, phone_can_write_index, phone_write_col, " 发送成功 ")
562-
self._adb.adb_put_back()
563-
else:
564-
self._adb.click_by_text_after_refresh("发送")
565-
566-
print(' !! <== 发送成功 <== ')
567-
write_to_excel(phone_file_path, phone_can_write_index, phone_write_col, "发送成功")
568-
time.sleep(3)
569-
self._adb.adb_put_back()
570-
if self._adb.find_node_by_text('添加到通讯录'):
571-
print("操作可能太频繁被限制,建议换号或者等会再试")
586+
print(' !! <== 发送成功 <== ')
587+
write_to_excel(phone_file_path, phone_can_write_index, phone_write_col, "发送成功")
588+
time.sleep(3)
572589
self._adb.adb_put_back()
590+
if self._adb.find_node_by_text('添加到通讯录'):
591+
print("操作可能太频繁被限制,建议换号或者等会再试")
592+
self._adb.adb_put_back()
573593

574594

575595

576-
elif self._adb.find_node_by_text('发消息'):
577-
print(' <== 已经是好友 无需再次添加 <== ')
578-
write_to_excel(phone_file_path, phone_can_write_index, phone_write_col, "已经是好友")
579-
self._adb.adb_put_back()
596+
elif self._adb.find_node_by_text('发消息'):
597+
print(' <== 已经是好友 无需再次添加 <== ')
598+
write_to_excel(phone_file_path, phone_can_write_index, phone_write_col, "已经是好友")
599+
self._adb.adb_put_back()
580600

581-
# elif self._adb.find_node_by_text('同时拥有微信和企业微信'):
582-
# print(' <== 同时拥有微信和企业微信 <== ')
583-
# self.push('failed', phone + '同时拥有微信和企业微信')
584-
# self._adb.adb_put_back()
601+
# elif self._adb.find_node_by_text('同时拥有微信和企业微信'):
602+
# print(' <== 同时拥有微信和企业微信 <== ')
603+
# self.push('failed', phone + '同时拥有微信和企业微信')
604+
# self._adb.adb_put_back()
585605

586-
# elif self._adb.find_node_by_text('该用户不存在') or self._adb.find_node_by_text('被搜帐号状态异常,无法显示'):
587-
# print(' <== 该用户不存在 或 帐号异常 <== ')
588-
# write_to_excel(phone_file_path, phone_can_write_index, phone_write_col, "该用户不存在")
606+
# elif self._adb.find_node_by_text('该用户不存在') or self._adb.find_node_by_text('被搜帐号状态异常,无法显示'):
607+
# print(' <== 该用户不存在 或 帐号异常 <== ')
608+
# write_to_excel(phone_file_path, phone_can_write_index, phone_write_col, "该用户不存在")
589609

590-
# 清空已输入的字符
591-
self.clean_phone()
592-
try:
610+
# 清空已输入的字符
593611
self.clean_phone()
594-
except:
612+
try:
613+
self.clean_phone()
614+
except:
615+
pass
616+
except Exception:
595617
pass
596618

597619
def fuck(self):
@@ -631,14 +653,17 @@ def main(self):
631653
#读取手机号数据
632654
phone_datas = [get_keywords_data(phoe_tables, i, phone_get_col) for i in
633655
range(1, phoe_tables.nrows)]
634-
for phone in phone_datas:
656+
for index, phone in enumerate(phone_datas):
657+
print("手机号总数:{},当前已添加至第{}个号码".format(len(phone_datas), index + 1))
635658
try:
636659
self._adb.wake_up_the_screen()
637660
print("唤醒屏幕")
638661
# # # 解锁 此处只能滑动解锁
639662
time.sleep(2)
640663
self._adb.unlock()
641664
print("解锁成功")
665+
self._adb.return_home()
666+
print("返回桌面")
642667
self._adb.start_wechat()
643668
print("启动微信")
644669
self._adb.click_add_friend()
@@ -659,16 +684,33 @@ def test(self):
659684
间断时间较短
660685
:return:
661686
"""
687+
try:
688+
self._adb.wake_up_the_screen()
689+
print("唤醒屏幕")
690+
# # # 解锁 此处只能滑动解锁
691+
time.sleep(2)
692+
self._adb.unlock()
693+
print("解锁成功")
694+
self._adb.return_home()
695+
print("返回桌面")
696+
self._adb.start_wechat()
697+
print("启动微信")
698+
self._adb.click_add_friend()
699+
print("点击加号")
700+
self._adb.click_wechat_and_friend()
701+
print("点击那两个 微信号/手机号")
702+
except:
703+
pass
704+
662705
global phone_can_write_index
663706
self._adb.click_add_friend()
664707
# 点击那两个 微信号/手机号
665708
self._adb.click_wechat_and_friend()
666709
phone_datas = [get_keywords_data(phoe_tables, i, phone_get_col) for i in
667710
range(1, phoe_tables.nrows)]
668-
for phone in phone_datas:
669-
711+
for index, phone in enumerate(phone_datas):
712+
print("手机号总数:{},当前已添加至第{}个号码".format(len(phone_datas), index + 1))
670713
self.add_friends(phone)
671-
time.sleep(wait_time)
672714
phone_can_write_index +=1
673715
y = input("{}个电话号码已加完,是否关闭程序".format(len(phone_datas)))
674716
if y:
@@ -677,7 +719,9 @@ def test(self):
677719

678720
if __name__ == '__main__':
679721
fun = Main()
680-
chose = input("请选择运行模式 :1.长时间间隔模式,2:短时间间隔模式(此模式下建议等待时间为1s 保持屏幕亮了就可以)")
722+
chose = input("请选择运行模式 :")
723+
print("1.长时间间隔模式,2:短时间间隔模式(此模式下建议等待时间为1s 保持屏幕亮了就可以)")
724+
print("请注意:两个模式都需要确保手机屏幕在熄灭状态下启动!!")
681725
if chose == "1":
682726
fun.main()
683727
if chose == "2":

adb微信加好友/phone_number.xls

-20.5 KB
Binary file not shown.

python开发/new_spider.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# @Time : 2019/11/14 17:06
22
# @Author : Libuda
3-
# @FileName: 无密spider.py
3+
# @FileName: new_spiders.py
44
# @Software: PyCharm
55
# !/usr/bin/env python3
66
# -*- coding: utf-8 -*-

python开发/spider.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# @Time : 2019/11/14 17:06
22
# @Author : Libuda
3-
# @FileName: 无密spider.py
3+
# @FileName: new_spiders.py
44
# @Software: PyCharm
55
# !/usr/bin/env python3
66
# -*- coding: utf-8 -*-

新浪新闻爬虫/spider.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import time
2+
import jieba
3+
from selenium import webdriver
4+
5+
chrome_options = webdriver.ChromeOptions()
6+
chrome_options.add_argument('--headless')
7+
chrome_options.add_argument('--disable-gpu')
8+
chrome_options.add_argument('window-size=1200,1100')
9+
driver = webdriver.Chrome(chrome_options=chrome_options,
10+
executable_path=r'C:\Users\lenovo\PycharmProjects\Spider\chromedriver.exe')
11+
12+
url = "https://news.sina.com.cn/world/"
13+
driver.get(url)
14+
15+
titles = driver.find_elements_by_css_selector(".news-item > h2")
16+
for one in titles:
17+
print(one.text)

樊登读书脚本/link.xls

0 Bytes
Binary file not shown.

飞鱼脚本/new_spiders.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ def get_new_phone(start, end):
141141
end = time.strftime("%Y-%m-%d %H:%M:%S", end)
142142
print("当前时间段为:{}---{}".format(start, end))
143143
print("新爬取手机号{}个".format(len(res)))
144-
totle += res
144+
totle += len(res)
145145
print("手机号:{}".format(res))
146146
print("当前共爬取手机号:{}个".format(totle))
147147
return res
@@ -268,6 +268,8 @@ def register(phone_data):
268268
except Exception as e:
269269
pass
270270

271+
print("当前链接总数:{},已使用链接数:{}".format(link_tables.nrows - 1, totle_link))
272+
271273

272274
def main():
273275
crawl_count = 1
@@ -280,7 +282,6 @@ def main():
280282
phone_data = get_new_phone(start_date, end_date)
281283
y = input("是否设置完毕")
282284
register(phone_data)
283-
print("当前已使用链接数:{}".format(totle_link))
284285
crawl_count += 1
285286
print("=" * 30)
286287
else:
@@ -290,7 +291,6 @@ def main():
290291
phone_data = get_new_phone(end_date, times)
291292
end_date = times
292293
register(phone_data)
293-
print("当前已使用链接数:{}".format(totle_link))
294294
crawl_count += 1
295295
print("=" * 30)
296296

0 commit comments

Comments
 (0)