Skip to content

Commit 60f8419

Browse files
committed
1. 修改internetUtil.py为loginUtil.py
2. 加入查看雅思信息的脚本ielts_new.py
1 parent e52e8ab commit 60f8419

File tree

4 files changed

+182
-26
lines changed

4 files changed

+182
-26
lines changed

.idea/workspace.xml

+116-25
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ielts_news.py

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
#!/usr/bin/env python3
2+
# coding=utf-8
3+
__author__ = 'smallfly'
4+
5+
import requests
6+
from bs4 import BeautifulSoup
7+
8+
NEWS_ADDRESS = "https://ielts.etest.net.cn/allnews"
9+
10+
class NewsItem:
11+
12+
def __init__(self, date, title, url):
13+
self.__data = {
14+
"date": date,
15+
"title": title,
16+
"url": url
17+
}
18+
19+
def __repr__(self):
20+
return repr(self.__data)
21+
22+
def __getattr__(self, item):
23+
if item in self.__data:
24+
return self.__data[item]
25+
raise AttributeError("NewsItem has no attribute named {}.".format(item))
26+
27+
28+
def get_raw_news(address):
29+
resp = requests.get(address)
30+
if resp.ok:
31+
resp.encoding = "UTF-8"
32+
return resp.text
33+
else:
34+
return None
35+
36+
def parse_news(content):
37+
soup = BeautifulSoup(content)
38+
all_news_li = soup.find_all("li", {"class": "main-sub-act-new"})
39+
news_items = []
40+
for li in all_news_li:
41+
# 存有新闻链接a标签的span标签
42+
span_with_a_tag = li.contents[0]
43+
# 存有发布时间的span标签
44+
span_with_date = li.contents[1]
45+
# 存放新闻链接的a标签
46+
a_tag = span_with_a_tag.a
47+
date_string = span_with_date.string.strip()
48+
news_items.append(NewsItem(date_string[1: len(date_string) - 1], a_tag.string.strip(), a_tag["href"]))
49+
# print(span_with_date.string.strip(), a_tag.string, a_tag["href"])
50+
return news_items
51+
52+
def pretty_print(items):
53+
items.sort(key=lambda x: x.date, reverse=True)
54+
for item in items:
55+
print("Date:", item.date)
56+
print("Title:", item.title)
57+
print("URL:", item.url)
58+
print()
59+
60+
if __name__ == "__main__":
61+
content = get_raw_news(NEWS_ADDRESS)
62+
if content is not None:
63+
items = parse_news(content)
64+
pretty_print(items)

internetUtil.py loginUtil.py

File renamed without changes.

totalCodeLine.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def get_suffix():
2323
"""
2424
suffix_list = list()
2525
while True:
26-
suffix = input("input the suffix like .cpp(end input by empty line)\n")
26+
suffix = input("input the suffix like cpp(end input by empty line)\n")
2727
suffix = suffix.strip()
2828
if suffix == "":
2929
break
@@ -43,6 +43,7 @@ def get_line_count(root_path, suffix_list):
4343
# print(os.path.abspath(file))
4444
# 匹配后缀名
4545
file_suffix = os.path.splitext(file)[1]
46+
file_suffix = file_suffix.strip('.')
4647
if file_suffix in suffix_list:
4748
# 读取该文件
4849
with open(os.path.join(root, file)) as f:

0 commit comments

Comments
 (0)