关闭页面特效

1209-诗人信息&诗词注释&诗句显示美化

1|0今日进度


1|1诗人信息


 

1|2 诗词注释


爬取诗词注释

import requests from bs4 import BeautifulSoup from lxml import etree headers = {'user-agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.131 Safari/537.36'}#创建头部信息 pom_list=[] k=1 for i in range(1,1000): url='https://www.xungushici.com/shicis/cd-yuan-p-'+str(i) r=requests.get(url,headers=headers) content=r.content.decode('utf-8') soup = BeautifulSoup(content, 'html.parser') hed=soup.find('div',class_='col col-sm-12 col-lg-9') list=hed.find_all('div',class_="card mt-3") # print(len(list)) for it in list: content = {} #1.1获取单页所有诗集 href=it.find('h4',class_='card-title').a['href'] real_href='https://www.xungushici.com'+href title=it.find('h4',class_='card-title').a.text print(title) #2.1爬取诗词 r2 = requests.get(real_href, headers=headers) content2 = r2.content.decode('utf-8') soup2 = BeautifulSoup(content2, 'html.parser') zhu = "" if soup2.find('div',class_='card mt-3')==[]: zhu="" content['title'] = title content['zhu'] = zhu pom_list.append(content) print("" + str(k) + "") k = k + 1 continue card_div=soup2.find('div',class_='card mt-3') if card_div==None or card_div.find('div',class_='card-body')==[]: zhu="" content['title'] = title content['zhu'] = zhu pom_list.append(content) print("" + str(k) + "") k = k + 1 continue card_body=card_div.find('div',class_='card-body') p_list=card_body.find_all('p') flag=1 for it in p_list: if str(it).find('strong')!=-1 and it.find('strong').text=='注释': flag=0 continue if flag==0: zhu=zhu+str(it) if len(zhu)==0: zhu="" content['title']=title content['zhu']=zhu pom_list.append(content) print(""+str(k)+"") k=k+1 import xlwt xl = xlwt.Workbook() # 调用对象的add_sheet方法 sheet1 = xl.add_sheet('sheet1', cell_overwrite_ok=True) sheet1.write(0,0,"title") sheet1.write(0,12,'zhu') for i in range(0,len(pom_list)): sheet1.write(i+1,0,pom_list[i]['title']) sheet1.write(i+1, 12, pom_list[i]['zhu']) xl.save("yuan.xlsx") # print(pom_list)

展示效果

 

 前端页面展示

 

1|3 诗句美化


对句子按照句号分割展示,对于七言古诗按照逗号分行展示

 

 


__EOF__

作  者清风紫雪
出  处https://www.cnblogs.com/xiaofengzai/p/15669229.html
关于博主:编程路上的小学生,热爱技术,喜欢专研。评论和私信会在第一时间回复。或者直接私信我。
版权声明:署名 - 非商业性使用 - 禁止演绎,协议普通文本 | 协议法律文本
声援博主:如果您觉得文章对您有帮助,可以点击文章右下角推荐一下。您的鼓励是博主的最大动力!

posted @   清风紫雪  阅读(122)  评论(0编辑  收藏  举报
编辑推荐:
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
阅读排行:
· 周边上新:园子的第一款马克杯温暖上架
· 分享 3 个 .NET 开源的文件压缩处理库,助力快速实现文件压缩解压功能!
· Ollama——大语言模型本地部署的极速利器
· DeepSeek如何颠覆传统软件测试?测试工程师会被淘汰吗?
· 使用C#创建一个MCP客户端
历史上的今天:
2019-12-09 公文流转完成情况(一)
0
0
关注
跳至底部
点击右上角即可分享
微信分享提示