forked from gil9red/SimplePyScripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathempty_tags_stackoverflow.py
More file actions
70 lines (47 loc) · 1.86 KB
/
Copy pathempty_tags_stackoverflow.py
File metadata and controls
70 lines (47 loc) · 1.86 KB
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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
__author__ = 'ipetrash'
import time
from urllib.parse import quote
import grab
if __name__ == '__main__':
g = grab.Grab()
tag_list = set()
page = 1
while True:
try:
url = 'http://ru.stackoverflow.com/tags?page={}&tab=name'.format(page)
print('Go page (found tags: {}): {}'.format(len(tag_list), url))
g.go(url)
next_page = g.doc.select('//span[@class="page-numbers next"]')
if not next_page.exists():
break
for a in g.doc.select('//a[@class="post-tag"]'):
tag = a.text()
url = 'http://ru.stackoverflow.com/tags/{}/info'.format(quote(tag))
print(' Go tag: {}'.format(url))
tag_g = grab.Grab()
tag_g.go(url)
has_not_ref_guide = "Для этой метки до сих пор нет руководства по использованию." in tag_g.response.body
has_not_description = "Для этой метки до сих пор нет описания." in tag_g.response.body
if has_not_ref_guide or has_not_description:
tag_info = (
tag,
has_not_ref_guide, has_not_description,
url
)
tag_list.add(tag_info)
time.sleep(.3)
page += 1
time.sleep(1)
except Exception as e:
import traceback
# Сохраняем в переменную
tb = traceback.format_exc()
print('Error:\n{}'.format(tb))
print('Wait 60 sec.')
time.sleep(60)
print('Tags: {}.'.format(len(tag_list)))
for tag in tag_list:
print(*tag)
print(tag_list)