資源簡介
這是《Python數據挖掘課程》系列文章,前面很多文章都講解了分類、聚類算法,而這篇文章主要講解如何調用SnowNLP庫實現情感分析,處理的對象是豆瓣《肖申克救贖》的評論文本。文章比較基礎,希望對你有所幫助,提供些思路,也是自己教學的內容。如果文章中存在錯誤或不足之處,還請海涵。同時,推薦大家閱讀我以前的文章了解其他知識。
---------------------
作者:Eastmount
來源:CSDN
原文:https://blog.csdn.net/Eastmount/article/details/85118818
版權聲明:本文為博主原創文章,轉載請附上博文鏈接!
代碼片段和文件信息
#?coding=utf-8??
from?selenium?import?webdriver??
from?selenium.webdriver.common.keys?import?Keys??
import?selenium.webdriver.support.ui?as?ui??
from?selenium.webdriver.common.action_chains?import?ActionChains??
import?time??????
import?re??????
import?os
import?csv
#打開Firefox瀏覽器
driver?=?webdriver.Firefox()
i?=?0
while?i<1:
????num?=?i*20
????url?=?“https://movie.douban.com/subject/1292052/comments?start=“?+?str(num)?+“&limit=20&sort=new_score&status=P“
????print?url
????driver.get(url)
????#用戶姓名?超鏈接
????elem1?=?driver.find_elements_by_xpath(“//div[@class=‘avatar‘]/a“)
????for?n?in?elem1:
????????print?n.get_attribute(“title“)?
????????print?n.get_attribute(“href“)
????????
????#用戶評分
????elem2?=?driver.find_elements_by_xpath(“//span[@class=‘comment-info‘]/span[2
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件???????1394??2018-12-20?15:06??2018-12-20?情感分析\1.test-douban.py
?????文件???????2549??2018-12-20?16:29??2018-12-20?情感分析\2.test-douban2.py
?????文件????????592??2018-12-20?16:59??2018-12-20?情感分析\3.test-fenci.py
?????文件????????269??2018-12-21?09:43??2018-12-20?情感分析\4.test-snownlp01.py
?????文件????????718??2018-12-21?10:22??2018-12-20?情感分析\5.test-snownlp02.py
?????文件????????348??2018-12-21?10:37??2018-12-20?情感分析\6.test-snownlp03.py
?????文件????????520??2018-12-21?11:00??2018-12-20?情感分析\7.test-snownlp04.py
?????文件????????655??2018-12-21?11:10??2018-12-20?情感分析\8.test-snownlp05.py
?????文件??????28795??2018-12-20?16:37??2018-12-20?情感分析\data.txt
?????文件??????47753??2018-12-20?16:29??2018-12-20?情感分析\test-douban.csv
?????目錄??????????0??2018-12-21?11:01??2018-12-20?情感分析
-----------?---------??----------?-----??----
????????????????83593????????????????????11
- 上一篇:pyltp的wheel文件
- 下一篇:python開發環境 Anaconda2
評論
共有 條評論