Python制作古诗生成器

本文介绍了如何使用Python创建一个古诗生成器,通过scrapy爬取数据,处理后使用word2vec训练词向量,并结合文本生成器,旨在弘扬中国传统文化。
摘要由CSDN通过智能技术生成

前言:

          从学习Python这款语言开始,小编就感觉它真是无所不能呢!唐诗是我们中国的古老传承,但是现在欣赏它的越来越少了,所以今天我们就来用Python做一个古诗生成器,以此来弘扬我国传统文化~

准备:

  • Python3.6环境
  • 安装谷歌的word2vec模块
  • 推荐使用Pycharm作为编译器

具体步骤:

使用scrapy爬取古诗词网,总共爬取唐诗5000首

代码如下:
# -*- coding: utf-8 -*-
import scrapy
from quotesbot.items import ShiciItem
import re

class TextSpider(scrapy.Spider):
    name = 'XYX'
    start_urls = ['https://so.gushiwen.org/search.aspx?page=1',
                  'https://so.gushiwen.org/search.aspx?page=2',
                  'https://so.gushiwen.org/search.aspx?page=3',
                  'https://so.gushiwen.org/search.aspx?page=4',
                  'https://so.gushiwen.org/search.aspx?page=5',
                   'https://so.gushiwen.org/search.aspx?page=6',
                  'https://so.gushiwen.org/search.aspx?page=7',
                  'https://so.gushiwen.org/search.aspx?page=8',
                  'https://so.gushiwen.org/search.aspx?page=9',
                  'https://so.gushiwen.org/search.aspx?page=10',
              
  • 9
    点赞
  • 46
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值