Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to generate articles automatically in python

2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

This article will explain in detail how to automatically generate articles in python. The content of the article is of high quality, so the editor shares it for you as a reference. I hope you will have a certain understanding of the relevant knowledge after reading this article.

1. Let's see the results first.

Through the code to generate thousands of words of articles, but also quoted a large number of celebrity quotes, but also their own paragraph segmentation. Although some of them are nonsense if you look carefully, they are all the experience of dealing with the job, and copying and pasting is also writing, so why not use code to generate it?

two。 Code

Import os, re

Import random,readJSON

Data = readJSON. Read the JSON file ("data.json")

Celebrity quotes = data ["famous"] # a stands for front words, b for back words

Preceding words = data ["before"] # do some nonsense in front of celebrity quotes

Following words = data ['after'] # get some nonsense after celebrity quotes

Nonsense = data ['bosh'] # represents the main source of nonsense in the article

Xx = "Student Union quits"

Repetition = 2

Def shuffle traversal (list):

Global repeatability

Pool = list (list) * repetition

While True:

Random.shuffle (Pool)

For element in pool:

Yield element

The next nonsense = shuffle (nonsense)

The next famous quote = shuffle traversing (celebrity quotes)

Def, some celebrity quotes ():

Global's next famous quote

Xx = next (the next famous saying)

Xx = xx.replace ("a", random.choice)

Xx = xx.replace ("b", random.choice)

Return xx

Def adds another paragraph ():

Xx = "."

Xx + = "\ r\ n"

Xx + = ""

Return xx

If _ name__ = = "_ _ main__":

Xx = input ("Please enter the article topic:")

For x in xx:

Tmp = str ()

While (len (tmp))

< 6000 ) : 分支 = random.randint(0,100) if 分支 < 5: tmp += 另起一段() elif 分支 < 20 : tmp += 来点名人名言() else: tmp += next(下一句废话) tmp = tmp.replace("x",xx) print(tmp) 代码就这么长,相对于人工智能,自然语言处理来说,这些不要说太简单,一共就50行代码左右,该程序员在代码还调皮的使用了中文变量,有兴趣的同学可以去下载学习一下哦,源码放在参考链接和阅读原文当中 3.在线版本(网址放在文末) 当然对于有些小伙伴使用还是太麻烦,所以有给力的程序员又添砖加瓦给项目加上了在线版本(链接在文末),直接点击网址就可以生成文

On how to automatically generate articles in python to share here, I hope the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report