Ai
1 Star 0 Fork 1

高鑫/Python

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
Article_Sentiment.py 1.06 KB
一键复制 编辑 原始数据 按行查看 历史
randerson112358 提交于 2019-08-02 09:24 +08:00 . Update Article_Sentiment.py
#Get the sentiment of articles from the internet
#pip install newspaper3k
#pip install textblob
#pip install nltk
#Import the libraries
from textblob import TextBlob
import nltk
from newspaper import Article
#Get the article
url = 'https://everythingcomputerscience.com/'
article = Article(url)
# Do some NLP
article.download() #Downloads the link’s HTML content
article.parse() #Parse the article
nltk.download('punkt')#1 time download of the sentence tokenizer
article.nlp()# Keyword extraction wrapper
#Get the summary of the article
text = article.summary
#print text
print(text)
#Create Text Blob Object
#NOTE: You can treat TextBlob objects as if they were Python strings that learned how to do Natural Language Processing.
obj = TextBlob(text)
#returns the sentiment of text
#by returning a value between -1.0 and 1.0
sentiment = obj.sentiment.polarity
print(sentiment)
#Print if the article was neutral, positive, or negative
if sentiment == 0:
print('The text is neutral')
elif sentiment > 0:
print('The text is positive')
else:
print('The text is negative')
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/gaoxin1999/Python.git
git@gitee.com:gaoxin1999/Python.git
gaoxin1999
Python
Python
master

搜索帮助