forked from light-Life/Selenium-weight
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSelenium-weight.py
291 lines (208 loc) · 12.4 KB
/
Selenium-weight.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
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
# !/usr/bin/python
# -*- coding:utf-8 -*-
# author: huayang
# time: 2021.10.12-2021.11.4
import re
import os
import time
import json
import xlwt
import requests
import threading
from selenium import webdriver
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument("--headless")
browser = webdriver.Chrome(chrome_options=chrome_options)
print("""\033[0;36m请选择扫描的类型:
1 【单个扫描】
2 【批量扫描(url.txt)】
\033[0m""")
choice = input('请输入数字:')
if choice == '1':
url = input('url:')
if 'http://' in url:
url = url[7:]
elif 'https://' in url:
url = url[8:]
try:
browser.get('https://www.aizhan.com/cha/' + url)
html = str(browser.page_source)
Baidu_amount = re.findall('.*?baidurank_ip" class="red">(.*?)</span>.*?',html)#百度流量
print('\033[1;32m百度流量\033[0m',Baidu_amount[0])
Move_amout = re.findall('.*?baidurank_m_ip">(.*?)</span>.*?',html)#移动流量
print('\033[1;32m移动流量\033[0m',Move_amout[0])
Baidu = re.findall('.*?//statics.aizhan.com/images/br/(.*?).png.*?', html)#百度权重
print('\033[1;32m百度权重\033[0m',Baidu[0])
Move = re.findall('.*?//statics.aizhan.com/images/mbr/(.*?).png.*?',html)#移动权重
print('\033[1;32m移动权重\033[0m',Move[0])
Google = re.findall('.*?//statics.aizhan.com/images/pr/(.*?).png.*?',html)#谷歌权重
print('\033[1;32m谷歌权重\033[0m',Google[0])
Qihu360 = re.findall('.*?//statics.aizhan.com/images/360/(.*?).png.*?',html)#360权重
print('\033[1;32m360权重\033[0m',Qihu360[0])
Shenma = re.findall('.*?//statics.aizhan.com/images/sm/(.*?).png.*?', html)#神马权重
print('\033[1;32m神马权重\033[0m',Shenma[0])
Sougou = re.findall('.*?//statics.aizhan.com/images/sr/(.*?).png.*?', html)#搜狗权重
print('\033[1;32m搜狗权重\033[0m',Sougou[0])
Beian = re.findall('.*?icp_icp">(.*?)</a>.*?', html)#备案信息
print('\033[1;32m备案信息\033[0m',Beian[0])
Xingzhi = re.findall('.*?id="icp_type">(.*?)</span>.*?', html)#性质
print('\033[1;32m性质\033[0m',Xingzhi[0])
Mingcheng = re.findall('.*?icp_company">(.*?)</span>.*?', html)#名称
print('\033[1;32m名称\033[0m',Mingcheng[0])
except:
pass
elif choice == '2':
if os.access("url.txt", os.F_OK):
print('\033[1;32m>>>已检测到url.txt存在<<<\033[0m\n')
print("""\033[0;34m请选择导出类型:
1 【导出可用纯域名(按照补天规则:爱站权重百度1、移动1、谷歌3)】
2 【导出完整的权重文件.xls】\033[0m""")
choice = input('请输入数字:')
if choice == '1':
localtime = time.localtime(time.time())
time = time.strftime("%Y%m%d%H%M%S", time.localtime())
print('\n\033[1;32m[+]正在创建'+time+'.txt\033[0m')
urls = open('url.txt')
for i in urls.readlines():
url = i.rstrip("\n")
if url == '': #避免空字符
break
else:
if 'http://' in url:
url = url[7:]
elif 'https://' in url:
url = url[8:]
try:
print('\n\033[1;31m》》》\033[0m'+url+'\033[1;31m《《《\033[0m\n')
browser.get('https://www.aizhan.com/cha/' + url)
html = str(browser.page_source)
Baidu_amount = re.findall('.*?baidurank_ip" class="red">(.*?)</span>.*?', html) # 百度流量
print('\033[1;32m百度流量\033[0m', Baidu_amount[0])
Move_amout = re.findall('.*?baidurank_m_ip">(.*?)</span>.*?', html) # 移动流量
print('\033[1;32m移动流量\033[0m', Move_amout[0])
Baidu = re.findall('.*?//statics.aizhan.com/images/br/(.*?).png.*?', html) # 百度权重
print('\033[1;32m百度权重\033[0m', Baidu[0])
Move = re.findall('.*?//statics.aizhan.com/images/mbr/(.*?).png.*?', html) # 移动权重
print('\033[1;32m移动权重\033[0m', Move[0])
Google = re.findall('.*?//statics.aizhan.com/images/pr/(.*?).png.*?', html) # 谷歌权重
print('\033[1;32m谷歌权重\033[0m', Google[0])
Qihu360 = re.findall('.*?//statics.aizhan.com/images/360/(.*?).png.*?', html) # 360权重
print('\033[1;32m360权重\033[0m', Qihu360[0])
Shenma = re.findall('.*?//statics.aizhan.com/images/sm/(.*?).png.*?', html) # 神马权重
print('\033[1;32m神马权重\033[0m', Shenma[0])
Sougou = re.findall('.*?//statics.aizhan.com/images/sr/(.*?).png.*?', html) # 搜狗权重
print('\033[1;32m搜狗权重\033[0m', Sougou[0])
Beian = re.findall('.*?icp_icp">(.*?)</a>.*?', html) # 备案信息
print('\033[1;32m备案信息\033[0m', Beian[0])
Xingzhi = re.findall('.*?id="icp_type">(.*?)</span>.*?', html) # 性质
print('\033[1;32m性质\033[0m', Xingzhi[0])
Mingcheng = re.findall('.*?icp_company">(.*?)</span>.*?', html) # 名称
print('\033[1;32m名称\033[0m', Mingcheng[0])
if str(Baidu[0]) > '0':
#print(url)
with open('test.txt', 'a')as f:
f.write(str(url) + '\n')
print('\n\033[1;32m[+]正在写入:\033[0m', url)
elif str(Move[0]) > '0':
#print(url)
with open('test.txt', 'a')as f:
f.write(str(url) + '\n')
print('\n\033[1;32m[+]正在写入:\033[0m', url)
elif str(Google[0]) >= '3':
#print(url)
with open('test.txt', 'a')as f:
f.write(str(url) + '\n')
print('\n\033[1;32m[+]正在写入:\033[0m', url)
except:
pass
elif choice == '2':
if os.access("url.txt", os.F_OK):
print('\033[1;32m>>>已检测到url.txt存在<<<\033[0m\n')
if os.access("权重.xls", os.F_OK):
print('\n\033[1;31m[○・`Д´・ ○]已存在"权重.xls",请更改后重试\033[0m\n')
else:
urls = open('url.txt')
global number # 定义一个全局变量
number = 1
workbook = xlwt.Workbook(encoding='utf-8') # 工作簿
worksheet = workbook.add_sheet('网站权重') # 工作表
# 创建颜色
pattern = xlwt.Pattern() # 创建模式对象
pattern.pattern = xlwt.Pattern.SOLID_PATTERN
pattern.pattern_fore_colour = 5 # 设置模式颜色
style = xlwt.XFStyle() # 创建样式对象
style.pattern = pattern # 将模式加入到样式对象
# 写入头部数据
worksheet.write(0, 0, '域名', style)
worksheet.write(0, 1, '百度流量', style)
worksheet.write(0, 2, '移动流量', style)
worksheet.write(0, 3, '百度权重', style)
worksheet.write(0, 4, '移动权重', style)
worksheet.write(0, 5, '谷歌权重', style)
worksheet.write(0, 6, '360权重', style)
worksheet.write(0, 7, '神马权重', style)
worksheet.write(0, 8, '搜狗权重', style)
worksheet.write(0, 9, '备案信息', style)
worksheet.write(0, 10, '性质', style)
worksheet.write(0, 11, '名称', style)
for i in urls.readlines():
url = i.rstrip("\n")
if url == '': #以免传入空字符
break
else:
if 'http://' in url: \
url = url[7:]
elif 'https://' in url:
url = url[8:]
print('\n\033[1;31m》》》\033[0m' + url + '\033[1;31m《《《\033[0m\n')
worksheet.write(number, 0, i)
browser.get('https://www.aizhan.com/cha/' + url)
html = str(browser.page_source)
Baidu_amount = re.findall('.*?baidurank_ip" class="red">(.*?)</span>.*?', html) # 百度流量
print('\033[1;32m百度流量\033[0m', Baidu_amount[0])
worksheet.write(number, 1, Baidu_amount[0])
Move_amout = re.findall('.*?baidurank_m_ip">(.*?)</span>.*?', html) # 移动流量
print('\033[1;32m移动流量\033[0m', Move_amout[0])
worksheet.write(number, 2, Move_amout[0])
Baidu = re.findall('.*?//statics.aizhan.com/images/br/(.*?).png.*?', html) # 百度权重
print('\033[1;32m百度权重\033[0m', Baidu[0])
worksheet.write(number, 3, Baidu[0])
Move = re.findall('.*?//statics.aizhan.com/images/mbr/(.*?).png.*?', html) # 移动权重
print('\033[1;32m移动权重\033[0m', Move[0])
worksheet.write(number, 4, Move[0])
Google = re.findall('.*?//statics.aizhan.com/images/pr/(.*?).png.*?', html) # 谷歌权重
print('\033[1;32m谷歌权重\033[0m', Google[0])
worksheet.write(number, 5, Google[0])
Qihu360 = re.findall('.*?//statics.aizhan.com/images/360/(.*?).png.*?', html) # 360权重
print('\033[1;32m360权重\033[0m', Qihu360[0])
worksheet.write(number, 6, Qihu360[0])
Shenma = re.findall('.*?//statics.aizhan.com/images/sm/(.*?).png.*?', html) # 神马权重
print('\033[1;32m神马权重\033[0m', Shenma[0])
worksheet.write(number, 7, Shenma[0])
Sougou = re.findall('.*?//statics.aizhan.com/images/sr/(.*?).png.*?', html) # 搜狗权重
print('\033[1;32m搜狗权重\033[0m', Sougou[0])
worksheet.write(number, 8, Sougou[0])
Beian = re.findall('.*?icp_icp">(.*?)</a>.*?', html) # 备案信息
print('\033[1;32m备案信息\033[0m', Beian)
worksheet.write(number, 9, Beian)
Xingzhi = re.findall('.*?id="icp_type">(.*?)</span>.*?', html) # 性质
print('\033[1;32m性质\033[0m', Xingzhi)
worksheet.write(number, 10, Xingzhi)
Mingcheng = re.findall('.*?icp_company">(.*?)</span>.*?', html) # 名称
print('\033[1;32m名称\033[0m', Mingcheng)
worksheet.write(number, 11, Mingcheng)
# 设置单元格的宽度
worksheet.col(0).width = 320 * 20
worksheet.col(1).width = 240 * 20
worksheet.col(2).width = 240 * 20
worksheet.col(9).width = 320 * 20
worksheet.col(11).width = 800 * 20
number = number + 1
# 保存文件
workbook.save('权重.xls')
else:
print('\n\033[3;31m哼塔[○・`Д´・ ○]\033[0m')
else:
print('\n\033[3;31m[○・`Д´・ ○]未检测到url.txt\033[0m')
else:
print('\n\033[3;31m[○・`Д´・ ○]\033[0m')