Skip to content

Commit

Permalink
Update getInfo.py
Browse files Browse the repository at this point in the history
  • Loading branch information
rcy1314 authored May 4, 2024
1 parent 07b361b commit 69c35a9
Showing 1 changed file with 11 additions and 13 deletions.
24 changes: 11 additions & 13 deletions getInfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

soup = BeautifulSoup(open('result.html'),"html.parser")
titleArr = soup.select('.u')

#标题
if titleArr:
headerTitle = titleArr[0].get_text()
Expand All @@ -13,8 +14,8 @@
newsStr = ""
newsElement = soup.select('.news-wrap > .line')
for div in newsElement:
news = div.get_text() + '\n'
newsStr += news
news = div.get_text() + '\n'
newsStr += news
formatText += newsStr + '\n'

#历史上的今天
Expand All @@ -24,15 +25,12 @@
else:
historyTitle = 'Default History Title'
formatText += historyTitle + '\n'

historyArr = soup.select('.history-wrap > .line a')
index = 0
history = ''

for a in historyArr:
for a in soup.select('.history-wrap > .line a'):
index += 1
history += str(index) + '. ' + a.get_text() + '\n'

formatText = formatText + history + '\n'

#时间进度条
Expand All @@ -41,15 +39,15 @@
progress = '时间进度条: ' + progressArr[0].get_text()
else:
progress = '时间进度条: N/A'
progress_text = soup.select('.line')[-1].get_text()
formatText += progress + '\n'

lineArr = soup.select('.line')
if lineArr:
progress_text = lineArr[-1].get_text()
else:
progress_text = 'N/A'
formatText += progress_text + '\n'

filename = 'result.txt'
with open (filename,'w') as file:
file.write(formatText)






0 comments on commit 69c35a9

Please sign in to comment.