代码拉取完成,页面将自动刷新
#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')
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。