-
Notifications
You must be signed in to change notification settings - Fork 42
Expand file tree
/
Copy pathempty_tags_stackoverflow.py
More file actions
75 lines (52 loc) · 1.9 KB
/
Copy pathempty_tags_stackoverflow.py
File metadata and controls
75 lines (52 loc) · 1.9 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
71
72
73
74
75
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
__author__ = "ipetrash"
import time
import traceback
from urllib.parse import quote
import grab
if __name__ == "__main__":
g = grab.Grab()
tag_list = set()
page = 1
while True:
try:
url = f"http://ru.stackoverflow.com/tags?page={page}&tab=name"
print(f"Go page (found tags: {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 = f"http://ru.stackoverflow.com/tags/{quote(tag)}/info"
print(f" Go tag: {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(0.3)
page += 1
time.sleep(1)
except Exception as e:
# Сохраняем в переменную
tb = traceback.format_exc()
print(f"Error:\n{tb}")
print("Wait 60 sec.")
time.sleep(60)
print(f"Tags: {len(tag_list)}.")
for tag in tag_list:
print(*tag)
print(tag_list)