-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmeizu.py
164 lines (143 loc) · 6.47 KB
/
meizu.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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
# -*- coding: utf-8 -*-
"""
Spyder Editor
This is a temporary script file.
"""
from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.keys import Keys
from PIL import Image
from selenium.common.exceptions import NoSuchElementException
import time, pickle, cv2
def partshot(webdrv,element,filename):
webdrv.save_screenshot(filename) #shot entire page
rec=element.rect
points=[rec['x'],rec['y'],rec['x']+rec['width']-5,rec['y']+rec['height']-23]
scr_img=Image.open(filename)
scr_img.crop(points).save(filename) #crop partial imge
def discal():
#构造一个3×3的结构元素
element = cv2.getStructuringElement(cv2.MORPH_RECT,(3, 3))
foo1 = cv2.imread('foo1.png',0);
dilate = cv2.dilate(foo1, element)
erode = cv2.erode(foo1, element)
#将两幅图像相减获得边,第一个参数是膨胀后的图像,第二个参数是腐蚀后的图像
foo1 = cv2.absdiff(dilate,erode);
foo2 = cv2.imread('foo2.png',0);
dilate = cv2.dilate(foo2, element)
erode = cv2.erode(foo2, element)
#将两幅图像相减获得边,第一个参数是膨胀后的图像,第二个参数是腐蚀后的图像
foo2 = cv2.absdiff(dilate,erode);
result = cv2.absdiff(foo2,foo1);
#上面得到的结果是灰度图,将其二值化以便更清楚的观察结果
retval, result = cv2.threshold(result, 40, 255, cv2.THRESH_BINARY);
locx=result.nonzero()[1]
dis = max(locx)-51
cv2.imwrite('foo0.jpg',cv2.bitwise_not(result))
#print(dis)
return dis
#profile = webdriver.FirefoxProfile()
#profile.set_preference("general.useragent.override", # Mobile phone
# "Mozilla/5.0 (Linux; U; Android 6.0.1; zh-cn; MI 5LTE Build/KTU84P) AppleWebKit/537.36 (KHTML, like Gecko)Version/4.0 MQQBrowser/6.9 Mobile Safari/537.36")
fox=webdriver.Firefox()
#mycookies= pickle.load(open("cookies.pkl", "rb"))
fox.get("https://login.flyme.cn")
fox.set_window_size(860,680)
#for cookie in mycookies:
# fox.add_cookie(cookie)
fox.implicitly_wait(3)
try:
buybtn=fox.find_element_by_css_selector('a#J_btnBuy')
buybtn.click()
except:
pass
if fox.title=="验证码登录":
tepbtn=fox.find_element_by_css_selector('a#toAccountLogin')
tepbtn.click()
if fox.title=="登录Flyme 账号":
fox.find_element_by_css_selector('input#account').send_keys("********")
fox.find_element_by_css_selector('input#password').send_keys("*********")
slider=fox.find_element_by_css_selector('div[class="gt_slider_knob gt_show"]')
gt_box=fox.find_element_by_css_selector('div.gt_box')
span=''
while span!="验证通过:" :#fox.title=="登录Flyme 账号":
#time.sleep(1) #等待人工验证
#'''
time.sleep(2)
if span=="出现错误:":
fox.refresh()
fox.implicitly_wait(5)
span=''
slider=fox.find_element_by_css_selector('div[class="gt_slider_knob gt_show"]')
gt_box=fox.find_element_by_css_selector('div.gt_box')
if span=="验证失败:":
fox.find_element_by_css_selector('div.gt_bottom>a.gt_refresh_button').click()
#ActionChains(fox).move_by_offset(-200,-200).perform()
#if span=="再来一次:" or span=="尝试过多:":
ActionChains(fox).move_to_element(slider).perform()
time.sleep(2)
partshot(fox,gt_box,'foo1.png')
ActionChains(fox).click_and_hold(slider).perform()
time.sleep(0.5)
partshot(fox,gt_box,'foo2.png')
time.sleep(1)
#ActionChains(fox).release(slider).perform()
try:
offset = discal()
print(offset)
#for i in range(1,offset,3):
ActionChains(fox).move_by_offset(offset,0).perform()
#ActionChains(fox).release(slider).perform()
except ValueError:
#fox.refresh()
#fox.implicitly_wait(6)
pass
ActionChains(fox).release(slider).perform()
#continue
#ActionChains(fox).move_to_element(slider).perform()
#ActionChains(fox).click_and_hold(slider).perform()
#ActionChains(fox).move_by_offset(offset,0).perform()
#ActionChains(fox).release(slider).perform()
time.sleep(0.5)
#span=fox.find_element_by_css_selector('span.gt_info_type').text
try:
span=fox.find_element_by_xpath('//div[@class="gt_info_text"]/span').text #XPath
except NoSuchElementException as e:
print(e)
span ==''
if span!='': print(span)
fox.find_element_by_xpath('//span[@class="mzchkbox"]/span/i').click()
fox.find_element_by_css_selector('a[id="login"]').click()
'''
fox.find_element_by_css_selector('input[placeholder="省/直辖市"]').click();
fox.find_element_by_xpath('//div[@class="mz-downmenu"]/ul/li[24]').click(); #河北省24, 山西省28
fox.find_element_by_css_selector('input[placeholder="城市"]').click();
fox.find_element_by_xpath('//div[@class="mz-downmenu"][2]/ul/li[11]').click(); #秦皇岛11, 太原3
fox.find_element_by_css_selector('input[placeholder="区/县"]').click();
fox.find_element_by_xpath('//div[@class="mz-downmenu"][3]/ul/li[1]').click(); #海港区1, 万柏林区5
fox.find_element_by_css_selector('input[placeholder="乡镇/街道"]').click();
fox.find_element_by_xpath('//div[@class="mz-downmenu"][4]/ul/li[10]').click(); #白塔岭10, 兴华街4
fox.find_element_by_css_selector('input[id="addressFormDetail"]').send_keys("燕山大学西校区")
buybtn=fox.find_element_by_css_selector('a[id="J_btnBuy"]')
buybtn.click()
fox.implicitly_wait(9) #9秒内如果网页加载完成则不再等待
addbtn=fox.find_element_by_css_selector('div[id="addressOpenBtn"]')
addbtn.location_once_scrolled_into_view
addbtn.click()
fox.find_element_by_css_selector('input[id="addressFormName"]').send_keys("牛延强")
fox.find_element_by_css_selector('input[id="addressFormPhone"]').send_keys("13930369014")
province = fox.find_element_by_css_selector('input[placeholder="省/直辖市"]')
province.click()
downmenu=fox.find_element_by_css_selector('div[class="mz-downmenu"]')
dic=downmenu.get_attribute("stytle")
print (dic)
#print (dic["display"])
downmenu.find_element_by_link_text('河北省').location_once_scrolled_into_view
#picrange.screenshot('foo.png')
#inputbox=fox.find_element_by_css_selector('input[name="wd"]')
#btn=fox.find_element_by_css_selector('input[class="bg s_btn"]')
#inputbox.send_keys("diarybook.site")
#btn.click()
#time.sleep(15)
#fox.quit()
'''