-
Notifications
You must be signed in to change notification settings - Fork 4
/
increase_readed.py
117 lines (90 loc) · 3.49 KB
/
increase_readed.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
#!/usr/bin/python3
import fire
from tool.spider.ReadURL import ReadURL
from time import sleep
# 增加某用户的CSDN阅读量, 发现是每天都能去增加一次
header = {
'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64; rv:67.0) Gecko/20100101 Firefox/67.0',
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
'Accept-Language': 'zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2',
'Accept-Encoding': 'gzip, deflate, br',
'DNT': '1',
'Connection': 'keep-alive',
'Upgrade-Insecure-Requests': '1',
'Cache-Control': 'max-age=0',
}
pattern = ' \033[0;32m%s\033[0m '
username = 'kcp606'
root_url = 'https://blog.csdn.net/' + username
blog_root_url = root_url + '/article/list'
def read_blog(list_url) -> bool:
"""读取页的URL得到每个博客URL 返回是否有该页存在"""
print(list_url)
read_url = ReadURL(list_url, header)
soup = read_url.analysis_html()
title_list = soup.find_all('h4')
hasArticle = False
for line in title_list:
tag = ReadURL.get_element(str(line), 'target')
if tag == '_blank':
line = str(line)
temp = line.split(' href="')[1]
url = temp.split('" target=')[0]
if "kcp606" not in url:
continue
read_url.url = url
hasArticle = True
read_url.analysis_html()
return hasArticle
def show_info(info_url):
""" 展示用户信息 """
read_url = ReadURL(info_url, header)
soup = read_url.analysis_html()
title_list = soup.find_all('div')
show_level = False
for line in title_list:
class_type = ReadURL.get_element(str(line), 'class')
if class_type is None:
continue
if 'item-tiling' in class_type:
first_temp = str(line).split('class="count"')
print_info('\t原创', first_temp[1].split('</')[0][1:])
print_info('粉丝', first_temp[2].split('</')[0][10:])
print_info('喜欢', first_temp[3].split('</')[0][1:])
print_info('评论', first_temp[4].split('</')[0][1:])
if 'level-' in str(line) and not show_level:
print_info('等级', str(line).split('level-')[1][0])
show_level = True
if 'grade-box clearfix' in class_type:
# print_info('等级', str(line).split(',点击查看等级说明')[0].split('target="_blank" title="')[1])
print_info('访问', str(line).split('<dd title="')[1].split('">')[0])
# print_info('积分', str(line).split('<dd title="')[2].split('">')[0])
print_info('排名', str(line).split('<dl title="')[1].split('">')[0])
print()
def print_info(title, value):
print(title + pattern % value, end='')
def seek_every_blog():
"""遍历所有的page"""
count = 1
list_url = blog_root_url + '/' + str(count)
while read_blog(list_url):
count += 1
list_url = blog_root_url + '/' + str(count)
def show_help():
start = '\033[0;32m'
end = '\033[0m'
print("%-26s %-20s" % (start + "-h" + end, "帮助"))
print("%-26s %-20s" % (start + "-l " + end, "死循环刷阅读量"))
print("%-26s %-20s" % (start + "-s" + end, "展示个人信息"))
def main(action=None):
if action is None:
seek_every_blog()
if action == '-l':
while True:
seek_every_blog()
sleep(600)
if action == '-h':
show_help()
if action == '-s':
show_info(root_url)
fire.Fire(main)