forked from queensun/Nyspider
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaso100_ui_v2.py
253 lines (236 loc) · 10.8 KB
/
aso100_ui_v2.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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'mainwindow.ui'
#
# Created by: PyQt5 UI code generator 5.4.1
#
# WARNING! All changes made in this file will be lost!
from PyQt5 import QtCore, QtGui, QtWidgets
import requests
from bs4 import BeautifulSoup
from openpyxl import Workbook
import time
from selenium import webdriver
import os
import calendar
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(957, 558)
self.centralWidget = QtWidgets.QWidget(MainWindow)
self.centralWidget.setObjectName("centralWidget")
self.label = QtWidgets.QLabel(self.centralWidget)
self.label.setGeometry(QtCore.QRect(10, 60, 64, 20))
self.label.setObjectName("label")
self.label_2 = QtWidgets.QLabel(self.centralWidget)
self.label_2.setGeometry(QtCore.QRect(150, 60, 91, 20))
self.label_2.setObjectName("label_2")
self.label_3 = QtWidgets.QLabel(self.centralWidget)
self.label_3.setGeometry(QtCore.QRect(490, 60, 64, 20))
self.label_3.setObjectName("label_3")
self.comboBox = QtWidgets.QComboBox(self.centralWidget)
self.comboBox.setGeometry(QtCore.QRect(60, 60, 85, 30))
self.comboBox.setObjectName("comboBox")
self.comboBox.addItem("")
self.comboBox.addItem("")
self.comboBox_2 = QtWidgets.QComboBox(self.centralWidget)
self.comboBox_2.setGeometry(QtCore.QRect(230, 60, 81, 30))
self.comboBox_2.setObjectName("comboBox_2")
self.comboBox_2.addItem("")
self.comboBox_2.addItem("")
self.comboBox_2.addItem("")
self.comboBox_3 = QtWidgets.QComboBox(self.centralWidget)
self.comboBox_3.setGeometry(QtCore.QRect(540, 60, 121, 30))
self.comboBox_3.setObjectName("comboBox_3")
self.pushButton = QtWidgets.QPushButton(self.centralWidget)
self.pushButton.setGeometry(QtCore.QRect(850, 60, 96, 28))
self.pushButton.setObjectName("pushButton")
self.textBrowser = QtWidgets.QTextBrowser(self.centralWidget)
self.textBrowser.setGeometry(QtCore.QRect(10, 110, 841, 411))
self.textBrowser.setObjectName("textBrowser")
self.label_4 = QtWidgets.QLabel(self.centralWidget)
self.label_4.setGeometry(QtCore.QRect(320, 60, 64, 20))
self.label_4.setObjectName("label_4")
self.comboBox_4 = QtWidgets.QComboBox(self.centralWidget)
self.comboBox_4.setGeometry(QtCore.QRect(370, 60, 111, 30))
self.comboBox_4.setObjectName("comboBox_4")
self.comboBox_4.addItem("")
self.comboBox_4.addItem("")
self.comboBox_4.addItem("")
self.comboBox_4.addItem("")
self.comboBox_4.addItem("")
self.comboBox_4.addItem("")
self.year_combox=QtWidgets.QComboBox(self.centralWidget)
self.year_combox.setGeometry(QtCore.QRect(660, 60, 70, 30))
self.month_combox=QtWidgets.QComboBox(self.centralWidget)
self.month_combox.setGeometry(QtCore.QRect(732, 60, 50, 30))
self.day_combox=QtWidgets.QComboBox(self.centralWidget)
self.day_combox.setGeometry(QtCore.QRect(782, 60, 50, 30))
MainWindow.setCentralWidget(self.centralWidget)
self.menuBar = QtWidgets.QMenuBar(MainWindow)
self.menuBar.setGeometry(QtCore.QRect(0, 0, 857, 28))
self.menuBar.setObjectName("menuBar")
self.menu = QtWidgets.QMenu(self.menuBar)
self.menu.setObjectName("menu")
MainWindow.setMenuBar(self.menuBar)
self.action = QtWidgets.QAction(MainWindow)
self.action.setObjectName("action")
self.menu.addAction(self.action)
self.menuBar.addAction(self.menu.menuAction())
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))
self.label.setText(_translate("MainWindow", "设备:"))
self.label_2.setText(_translate("MainWindow", "榜单类型:"))
self.label_3.setText(_translate("MainWindow", "类别:"))
self.comboBox.setItemText(0, _translate("MainWindow", "iphone"))
self.comboBox.setItemText(1, _translate("MainWindow", "ipad"))
self.comboBox_2.setItemText(0, _translate("MainWindow", "付费"))
self.comboBox_2.setItemText(1, _translate("MainWindow", "免费"))
self.comboBox_2.setItemText(2, _translate("MainWindow", "畅销"))
self.pushButton.setText(_translate("MainWindow", "采集"))
self.label_4.setText(_translate("MainWindow", "地区:"))
self.comboBox_4.setItemText(0, _translate("MainWindow", "中国"))
self.comboBox_4.setItemText(1, _translate("MainWindow", "美国"))
self.comboBox_4.setItemText(2, _translate("MainWindow", "香港"))
self.comboBox_4.setItemText(3, _translate("MainWindow", "台湾"))
self.comboBox_4.setItemText(4, _translate("MainWindow", "日本"))
self.comboBox_4.setItemText(5, _translate("MainWindow", "韩国"))
self.menu.setTitle(_translate("MainWindow", "菜单"))
self.action.setText(_translate("MainWindow", "退出"))
class Aso100(QtWidgets.QMainWindow,Ui_MainWindow):
def __init__(self):
super(Aso100,self).__init__()
self.setupUi(self)
self.setWindowTitle("ASO100数据采集")
self.genre={'购物': '6024', '图书': '6018', '游戏 ': '6014', '导航':'6010', '商品指南': '6022', '工具': '6002', '教育': '6017', '商务': '6000', '效率': '6007', '娱乐': '6016', '美食佳饮': '6023', '体育': '6004', '新闻': '6009', '摄影与录像': '6008', '社交': '6005', '参考': '6006', '财务': '6015', '报刊杂志': '6021', '天气': '6001', '旅游': '6003', '音乐': '6011', '生活': '6012', '医疗': '6020', '健康健美': '6013'}
self.brand={'付费':'paid','免费':'free','畅销':'grossing'}
self.country_labels={'中国':'cn','香港':'hk','台湾':'tw','美国':'us','日本':'jp','韩国':'kr'}
self.basicInit()
def basicInit(self):
year=time.strftime("%Y",time.localtime())
for i in range(10):
self.year_combox.addItem(str(int(year)-i))
for i in range(12):
month=i+1
if month<10:
self.month_combox.addItem('0'+str(month))
else:
self.month_combox.addItem(str(month))
self.month_change()
self.pushButton.clicked.connect(self.getData)
self.month_combox.currentIndexChanged.connect(self.month_change)
self.year_combox.currentIndexChanged.connect(self.month_change)
month=time.strftime("%m",time.localtime())
self.month_combox.setCurrentIndex(int(month)-1)
day=time.strftime("%d",time.localtime())
self.day_combox.setCurrentIndex(int(day)-1)
self.action.triggered.connect(self.close)
for key in self.genre:
self.comboBox_3.addItem(key)
def month_change(self):
year=self.year_combox.currentText()
month=self.month_combox.currentText()
self.day_combox.clear()
days=calendar.monthrange(int(year),int(month))
for i in range(days[1]):
day=i+1
if day<10:
self.day_combox.addItem('0'+str(day))
else:
self.day_combox.addItem(str(day))
def getBrowser(self):
self.browser=webdriver.Firefox()#.Chrome("./chromedriver")
self.browser.get('http://aso100.com/account/signin')
self.browser.implicitly_wait(10)
'''
self.browser.find_element_by_id('username').send_keys('username')
self.browser.find_element_by_id('password').send_keys('passwd')
self.browser.find_element_by_id('submit').click()
'''
time.sleep(3)
def writeToExcel(self,data,filename):
excel=Workbook(write_only=True)
sheet=excel.create_sheet()
for item in data:
sheet.append(item)
excel.save(filename)
def parser(self,html):
if '请完成验证后继续访问' in html:
return False
table=BeautifulSoup(html,'html.parser').find_all('h5')
result=[]
for item in table:
item=item.get_text()
rank=item.split('.')[0]
name=item.replace('%s.'%rank,'')
app=[name,rank]
result.append(app)
return result
def inputCap(self):
box=QtWidgets.QMessageBox.question(self,"滑动验证","请在浏览器中验证",QtWidgets.QMessageBox.Ok)
if box==QtWidgets.QMessageBox.Ok:
return True
else:
return False
def login(self):
box=QtWidgets.QMessageBox.question(self,"登录","请在浏览器中登录",QtWidgets.QMessageBox.Ok)
if box==QtWidgets.QMessageBox.Ok:
return True
else:
return False
def getData(self):
de=self.comboBox.currentText()
key_brand=self.comboBox_2.currentText()
key_genre=self.comboBox_3.currentText()
country=self.comboBox_4.currentText()
country_type=self.country_labels[country]
year=self.year_combox.currentText()
month=self.month_combox.currentText()
day=self.day_combox.currentText()
date="%s-%s-%s"%(year,month,day)
url='http://aso100.com/rank/more/date/%s/device/%s/country/%s/brand/%s/genre/%s/?page='%(date,de,country_type,self.brand[key_brand],self.genre[key_genre])
startpage=1
result=[]
hour=time.strftime("_%H%M%S",time.localtime())
filename=date.replace('-','')+hour+'_'+de+'_'+key_brand+'_'+key_genre+'_'+country+'.xlsx'
try:
os.mkdir(country)
except:
pass
try:
os.mkdir("%s/%s"%(country,key_genre))
except:
pass
while startpage<9:
try:
self.browser.get(url+str(startpage))
except:
self.getBrowser()
self.login()
continue
time.sleep(3)
try:
html=self.browser.page_source
except:
self.getBrowser()
continue
apps=self.parser(html)
if apps==False:
self.inputCap()
continue
if len(apps)==0:
break
for app in apps:
result.append([de,key_brand]+app+[key_genre,country])
self.textBrowser.append(de+'-'+key_brand+'-'+key_genre+'-'+str(startpage)+'-ok\n')
startpage+=1
self.writeToExcel(result,'%s/%s/%s'%(country,key_genre,filename))
self.textBrowser.append(de+'-'+key_brand+'-'+key_genre+'-ok\n')
if __name__=='__main__':
import sys
app=QtWidgets.QApplication(sys.argv)
management=Aso100()
management.show()
sys.exit(app.exec_())