- 浏览: 374601 次
- 性别:
- 来自: 四川
文章分类
- 全部博客 (247)
- 数据库以及sql (11)
- java (48)
- 爬虫学习 (20)
- java编程 (28)
- python编程以及安装和配置 (27)
- oracle数据库 (32)
- mongodb基本操作 (4)
- linux学习 (7)
- easyUI (2)
- nodeJs (8)
- python学习 (16)
- 其他 (13)
- hadoop (1)
- svn (1)
- 汉字 (1)
- windows (2)
- jsp (5)
- fiddler (1)
- ETL (1)
- teamviewer (1)
- maven (4)
- GIT (2)
- datagrip (1)
- ocr (1)
- redis (3)
- mysql (3)
- linux (1)
- 数据服务 (0)
最新评论
================================jiekou.py
# coding=utf-8
'''
Created on 2017年5月9日
@author: chenkai
'''
import bottle
import urllib
import struct
from getscoretext import GetScore
def geturltoutf8(srcString):
unquotedString = urllib.unquote(srcString)
#print repr(unquotedString)
textString = unquotedString.decode('utf-8')
#print textString
return textString
@bottle.route('/score', method='POST')
def score():
data =bottle.request.body.readlines()#获取请求参数列表
#转换参数编码格式
pltext=geturltoutf8(data[0]) #第一个参数,URL编码转utf8
print pltext #打印请求参数值
#开始情感分析
result=GetScore(pltext) #这个功能是我写在getscoretext.py文件中的一个函数
print result
return result #返回参数
bottle.run(host='localhost', port=8083)
==================getscoretext.py代码
# coding=utf-8
'''
Created on 2017年5月9日
@author: chenkai
'''
from snownlp import SnowNLP
from nltk.collocations import BigramCollocationFinder
from nltk.metrics import BigramAssocMeasures
import re
import jieba
import jieba.analyse
import json
def GetScore(text):
#1.标点符号处理
text = re.sub("[\s+\.\!\/_,$%^*(+\"\']+|[+——!,。?、~@#¥%……&*()]+".decode("utf8"), "".decode("utf8"),text)
#2.结巴分词(关键词提取)
#listGJC=jieba.analyse.extract_tags(text, topK=20, withWeight=False, allowPOS=())
listGJC=jieba.cut(text,cut_all=False)
#print "关键词提取:",",".join(listGJC)
text_jieba="#".join(listGJC).split("#")
good=0.0
bad=0.0
sinple=0.0
sum=0.0
for j in text_jieba:
if SnowNLP(j).sentiments <= 0.38:
bad=bad+1
if SnowNLP(j).sentiments > 0.38 and SnowNLP(j).sentiments < 0.5 :
sinple=sinple+1
if SnowNLP(j).sentiments >= 0.5:
good=good+1
sum=sum+SnowNLP(j).sentiments
print j,"=",SnowNLP(j).sentiments
goodscore=good/len(text_jieba)
badscore=bad/len(text_jieba)
info={}
info["wordlength"]=len(text_jieba)
info["avgscore"]=sum/len(text_jieba)
info["goodpercent"]=goodscore
info["badpercent"]=badscore
info["sinplepercent"]=sinple/len(text_jieba)
if badscore>0.15:
info["result"]=1
else:
info["result"]=0
#list.append(info)
jsonStr = json.dumps(info)
return jsonStr
===========================java调用接口代码
package com.teamdev.jxbrowser.chromium.demo.other.天猫;
import java.net.URL;
import java.security.SecureRandom;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSession;
import javax.net.ssl.X509TrustManager;
import org.jsoup.helper.HttpConnection;
public class testscore {
//协议
public static void trustEveryone() {
try {
HttpsURLConnection
.setDefaultHostnameVerifier(new HostnameVerifier() {
public boolean verify(String hostname,
SSLSession session) {
return true;
}
});
SSLContext context = SSLContext.getInstance("TLS");
context.init(null, new X509TrustManager[] { new X509TrustManager() {
public void checkClientTrusted(X509Certificate[] chain,
String authType) throws CertificateException {
}
public void checkServerTrusted(X509Certificate[] chain,
String authType) throws CertificateException {
}
public X509Certificate[] getAcceptedIssuers() {
return new X509Certificate[0];
}
} }, new SecureRandom());
HttpsURLConnection.setDefaultSSLSocketFactory(context
.getSocketFactory());
} catch (Exception e) {
// e.printStackTrace();
}
}
//请求商品信息
public static String search(String text) throws Exception {
URL baseurl = new URL("http://localhost:8083/score");
trustEveryone();
org.jsoup.Connection conn = HttpConnection.connect(baseurl);
conn.timeout(10000);
conn.header("Accept", "*/*");
conn.header("Accept-Encoding", "gzip, deflate, br");
conn.header("Accept-Language", "zh-CN,zh;q=0.9");
conn.header("Connection", "keep-alive");
//conn.header("Host", "mdskip.taobao.com");
//conn.header("Referer", "https://detail.tmall.com/item.htm?id="+id);
//conn.header("Cookie", "thw=cn; t=a00d02c664bfb837ed72484a4c81b509; cna=Z2zxEk5cmzACATz97ObN6ov8; tg=0; ucn=unzbyun; enc=QGMlzseKJil6PL%2B9EBrcNAPJ1zsoZDXaYNm%2BJX2VHlYHBE8YfKw%2B%2B1a5R02Iruwh7HrAPubO94INS4g4nQ5Azg%3D%3D; tracknick=%5Cu68A6%5Cu6E38%5Cu5BFB%5Cu5EA6; lgc=%5Cu68A6%5Cu6E38%5Cu5BFB%5Cu5EA6; UM_distinctid=16566b104a5157-0b2e12dbec7a96-323b5903-100200-16566b104a6b0; hng=CN%7Czh-CN%7CCNY%7C156; miid=947420887426720300; x=e%3D1%26p%3D*%26s%3D0%26c%3D0%26f%3D0%26g%3D0%26t%3D0%26__ll%3D-1%26_ato%3D0; mt=ci=18_1&np=; cookie2=1c7db674ce04faf9d9d10eecc37faeea; _tb_token_=7eef3da3ae591; v=0; dnk=%5Cu68A6%5Cu6E38%5Cu5BFB%5Cu5EA6; unb=2515522037; uc1=cookie16=UIHiLt3xCS3yM2h4eKHS9lpEOw%3D%3D&cookie21=U%2BGCWk%2F7p4mBoUyS4E9C&cookie15=UtASsssmOIJ0bQ%3D%3D&existShop=false&pas=0&cookie14=UoTfLQFjjQxSGg%3D%3D&tag=8&lng=zh_CN; sg=%E5%BA%A674; _l_g_=Ug%3D%3D; skt=d85039103e9a8fc4; cookie1=VFdi4GN5svKzDAyUwgbmoE2X8eRTQusiTld1jf9kv2k%3D; csg=9b28e004; uc3=vt3=F8dBzrSFNJwfzcOT7IM%3D&id2=UU2zVX4u382s1Q%3D%3D&nk2=oHTaof9n%2ByM%3D&lg2=W5iHLLyFOGW7aA%3D%3D; existShop=MTUzNjI4MzUzMA%3D%3D; _cc_=VFC%2FuZ9ajQ%3D%3D; _nk_=%5Cu68A6%5Cu6E38%5Cu5BFB%5Cu5EA6; cookie17=UU2zVX4u382s1Q%3D%3D; isg=BC8v8o66qDfe0qzgFxWNOu2avkOVwqqZj5wh9UG82R6lkE-SSaQWRt5BFsAL7Ftu; _umdata=ED82BDCEC1AA6EB95DD9C2BFA38139DABBD97FE15A9C9936CBE3A614AD5D495278CF76D202BDA457CD43AD3E795C914C597301369918D8F1F05B885FD44466E4; x5sec=7b226d616c6c64657461696c736b69703b32223a223966376362353736643363623537396365393834376637346562343738633933434a4843794e7746454f655932714f516e2b2b5171674561444449314d5455314d6a49774d7a63374d513d3d227d");
//conn.header("upgrade-insecure-requests", "1");
conn.header("User-Agent","Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36");
conn.data("text",text);
conn.ignoreContentType(true);
String result = conn.post().text();
//JSONObject ajson = new JSONObject(result);
return result;
}
public static void main(String[] args) {
try {
System.out.println(search("什么都不送"));
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
# coding=utf-8
'''
Created on 2017年5月9日
@author: chenkai
'''
import bottle
import urllib
import struct
from getscoretext import GetScore
def geturltoutf8(srcString):
unquotedString = urllib.unquote(srcString)
#print repr(unquotedString)
textString = unquotedString.decode('utf-8')
#print textString
return textString
@bottle.route('/score', method='POST')
def score():
data =bottle.request.body.readlines()#获取请求参数列表
#转换参数编码格式
pltext=geturltoutf8(data[0]) #第一个参数,URL编码转utf8
print pltext #打印请求参数值
#开始情感分析
result=GetScore(pltext) #这个功能是我写在getscoretext.py文件中的一个函数
print result
return result #返回参数
bottle.run(host='localhost', port=8083)
==================getscoretext.py代码
# coding=utf-8
'''
Created on 2017年5月9日
@author: chenkai
'''
from snownlp import SnowNLP
from nltk.collocations import BigramCollocationFinder
from nltk.metrics import BigramAssocMeasures
import re
import jieba
import jieba.analyse
import json
def GetScore(text):
#1.标点符号处理
text = re.sub("[\s+\.\!\/_,$%^*(+\"\']+|[+——!,。?、~@#¥%……&*()]+".decode("utf8"), "".decode("utf8"),text)
#2.结巴分词(关键词提取)
#listGJC=jieba.analyse.extract_tags(text, topK=20, withWeight=False, allowPOS=())
listGJC=jieba.cut(text,cut_all=False)
#print "关键词提取:",",".join(listGJC)
text_jieba="#".join(listGJC).split("#")
good=0.0
bad=0.0
sinple=0.0
sum=0.0
for j in text_jieba:
if SnowNLP(j).sentiments <= 0.38:
bad=bad+1
if SnowNLP(j).sentiments > 0.38 and SnowNLP(j).sentiments < 0.5 :
sinple=sinple+1
if SnowNLP(j).sentiments >= 0.5:
good=good+1
sum=sum+SnowNLP(j).sentiments
print j,"=",SnowNLP(j).sentiments
goodscore=good/len(text_jieba)
badscore=bad/len(text_jieba)
info={}
info["wordlength"]=len(text_jieba)
info["avgscore"]=sum/len(text_jieba)
info["goodpercent"]=goodscore
info["badpercent"]=badscore
info["sinplepercent"]=sinple/len(text_jieba)
if badscore>0.15:
info["result"]=1
else:
info["result"]=0
#list.append(info)
jsonStr = json.dumps(info)
return jsonStr
===========================java调用接口代码
package com.teamdev.jxbrowser.chromium.demo.other.天猫;
import java.net.URL;
import java.security.SecureRandom;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSession;
import javax.net.ssl.X509TrustManager;
import org.jsoup.helper.HttpConnection;
public class testscore {
//协议
public static void trustEveryone() {
try {
HttpsURLConnection
.setDefaultHostnameVerifier(new HostnameVerifier() {
public boolean verify(String hostname,
SSLSession session) {
return true;
}
});
SSLContext context = SSLContext.getInstance("TLS");
context.init(null, new X509TrustManager[] { new X509TrustManager() {
public void checkClientTrusted(X509Certificate[] chain,
String authType) throws CertificateException {
}
public void checkServerTrusted(X509Certificate[] chain,
String authType) throws CertificateException {
}
public X509Certificate[] getAcceptedIssuers() {
return new X509Certificate[0];
}
} }, new SecureRandom());
HttpsURLConnection.setDefaultSSLSocketFactory(context
.getSocketFactory());
} catch (Exception e) {
// e.printStackTrace();
}
}
//请求商品信息
public static String search(String text) throws Exception {
URL baseurl = new URL("http://localhost:8083/score");
trustEveryone();
org.jsoup.Connection conn = HttpConnection.connect(baseurl);
conn.timeout(10000);
conn.header("Accept", "*/*");
conn.header("Accept-Encoding", "gzip, deflate, br");
conn.header("Accept-Language", "zh-CN,zh;q=0.9");
conn.header("Connection", "keep-alive");
//conn.header("Host", "mdskip.taobao.com");
//conn.header("Referer", "https://detail.tmall.com/item.htm?id="+id);
//conn.header("Cookie", "thw=cn; t=a00d02c664bfb837ed72484a4c81b509; cna=Z2zxEk5cmzACATz97ObN6ov8; tg=0; ucn=unzbyun; enc=QGMlzseKJil6PL%2B9EBrcNAPJ1zsoZDXaYNm%2BJX2VHlYHBE8YfKw%2B%2B1a5R02Iruwh7HrAPubO94INS4g4nQ5Azg%3D%3D; tracknick=%5Cu68A6%5Cu6E38%5Cu5BFB%5Cu5EA6; lgc=%5Cu68A6%5Cu6E38%5Cu5BFB%5Cu5EA6; UM_distinctid=16566b104a5157-0b2e12dbec7a96-323b5903-100200-16566b104a6b0; hng=CN%7Czh-CN%7CCNY%7C156; miid=947420887426720300; x=e%3D1%26p%3D*%26s%3D0%26c%3D0%26f%3D0%26g%3D0%26t%3D0%26__ll%3D-1%26_ato%3D0; mt=ci=18_1&np=; cookie2=1c7db674ce04faf9d9d10eecc37faeea; _tb_token_=7eef3da3ae591; v=0; dnk=%5Cu68A6%5Cu6E38%5Cu5BFB%5Cu5EA6; unb=2515522037; uc1=cookie16=UIHiLt3xCS3yM2h4eKHS9lpEOw%3D%3D&cookie21=U%2BGCWk%2F7p4mBoUyS4E9C&cookie15=UtASsssmOIJ0bQ%3D%3D&existShop=false&pas=0&cookie14=UoTfLQFjjQxSGg%3D%3D&tag=8&lng=zh_CN; sg=%E5%BA%A674; _l_g_=Ug%3D%3D; skt=d85039103e9a8fc4; cookie1=VFdi4GN5svKzDAyUwgbmoE2X8eRTQusiTld1jf9kv2k%3D; csg=9b28e004; uc3=vt3=F8dBzrSFNJwfzcOT7IM%3D&id2=UU2zVX4u382s1Q%3D%3D&nk2=oHTaof9n%2ByM%3D&lg2=W5iHLLyFOGW7aA%3D%3D; existShop=MTUzNjI4MzUzMA%3D%3D; _cc_=VFC%2FuZ9ajQ%3D%3D; _nk_=%5Cu68A6%5Cu6E38%5Cu5BFB%5Cu5EA6; cookie17=UU2zVX4u382s1Q%3D%3D; isg=BC8v8o66qDfe0qzgFxWNOu2avkOVwqqZj5wh9UG82R6lkE-SSaQWRt5BFsAL7Ftu; _umdata=ED82BDCEC1AA6EB95DD9C2BFA38139DABBD97FE15A9C9936CBE3A614AD5D495278CF76D202BDA457CD43AD3E795C914C597301369918D8F1F05B885FD44466E4; x5sec=7b226d616c6c64657461696c736b69703b32223a223966376362353736643363623537396365393834376637346562343738633933434a4843794e7746454f655932714f516e2b2b5171674561444449314d5455314d6a49774d7a63374d513d3d227d");
//conn.header("upgrade-insecure-requests", "1");
conn.header("User-Agent","Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36");
conn.data("text",text);
conn.ignoreContentType(true);
String result = conn.post().text();
//JSONObject ajson = new JSONObject(result);
return result;
}
public static void main(String[] args) {
try {
System.out.println(search("什么都不送"));
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
发表评论
-
Pycharm常用快捷键
2018-10-17 16:45 803pycharm常用快捷键 1、编辑(Editing) Ctr ... -
python连接oracle数据库报错PI-1047: 64-bit Oracle Client library cannot be loaded: "解决方案
2018-10-17 16:44 7219错误原因:instantclient版本为32位,需更换成64 ... -
pycharm安装第三方库的方式
2018-10-16 17:33 21051.点击settings之后再点击project下面的proj ... -
pycharm中配置中文头, 不用每次都写
2018-10-16 17:20 1867打开file->settings->Editor- ... -
python 中__name__ = '__main__' 的作用
2018-09-14 09:50 1685出自:https://www.cnblogs.com/alan ... -
python中的textblob库的作用说明
2018-09-14 09:40 3851TextBlob 是一款 Pythonic 的文本处理工具,用 ... -
python之bottle框架的get,post请求实例
2018-09-12 15:51 3655=======================get请求 # ... -
python中的请求参数乱码 解决
2018-09-12 15:39 1308import urllib def geturltoutf8 ... -
python 安装nltk
2018-09-07 18:02 33861、在cmd窗口中,进入到python的文件夹内的 Scrip ... -
python 情感分析
2018-09-07 17:05 1682转:https://blog.csdn.net/u011001 ... -
python结巴分词
2018-03-20 14:46 610# coding=utf-8 ''' Created on 2 ... -
anaconda安装与配置环境变量,以及anaconda是什么,有什么用。
2017-07-12 10:15 10688anaconda安装与配置环境变量: 官网:https://w ... -
python中利用adb shell 控制手机,完美解决中文输入问题
2017-06-03 10:25 53891.连接手机, 打开开发者选项, 连接USB, (如果需要记录 ... -
selenium设置网页文本框中文值报错解决方法
2017-03-20 10:06 1045selenium设置网页文本框中文值报错解决方法 elem = ... -
python多进程和多线程的区别
2017-03-14 17:33 1151多线程和多进程最大的 ...
相关推荐
- **内置模板引擎**:Bottle支持多种模板语言,如Bottle默认的SimpleTemplate,以及Jinja2等第三方模板引擎。 ### 2. 安装与基本使用 要开始使用Bottle,首先确保已安装Python,然后通过pip安装Bottle: ```bash ...
2. **模板引擎**:Bottle内置了基于字符串的简单模板引擎,同时也支持Jinja2这样的第三方模板库,用于动态生成HTML页面。 3. **HTTP请求与响应**:Bottle提供`request`对象来获取HTTP请求的数据,如查询参数、POST...
Python的Bottle框架是一款轻量级的Web应用开发框架,以其简洁、高效的特性深受开发者喜爱。本文将深入探讨Bottle的一些实用技巧,帮助开发者更好地利用这个框架构建Web服务。 首先,我们要了解Bottle中的URL路由...
- **API接口**:提供了易于第三方系统集成的API接口,增强了互操作性。 - **无状态**:接口调用时无需考虑上下文或当前状态,极大地降低了复杂度。 #### 二、关键概念 为了更好地理解和实施RESTful API,需要明确...
三、Bottle核心组件 1. **路由**:通过`@route()`装饰器定义URL模式,将HTTP请求映射到处理函数。 2. **视图**:处理函数即视图,负责处理请求并返回响应。可以是纯文本、HTML页面或重定向等。 3. **模板**:使用...
Python的Bottle框架是一个轻量级的Web服务器和框架,它支持构建RESTful API。在本文中,我们将讨论如何在Bottle框架中支持jQuery AJAX的RESTful风格的PUT和DELETE方法。 通常,Bottle框架默认只处理GET和POST请求,...
这部分介绍了 **Bottle** 自带的模板引擎的使用方法,以及如何与第三方模板引擎集成。 - **内置模板引擎**: 快速且易于使用,适合简单的页面渲染。 - **第三方模板**: 支持 mako、jinja2 和 cheetah 等高级模板系统...
Python的轻便Web框架Bottle是一个专为小型应用和快速开发而设计的框架。它的设计哲学强调简洁和易用性,这使得它成为了众多Python开发者的首选之一。与Flask框架一样,Bottle注重轻量级和最小化依赖,但同时提供了...
Python套件: 瓶子0.12.16 (稳定) SQLAlchemy(with bottle-sqlalchemy) latest Jinja2 latest NPM软件包: Axios 0.18+ (AJAX调用) PostCSS / Autoprefixer 7.2+ (自动CSS前缀) Babel 7+ (将ES6代码转换为...
2. **模板引擎**:Bottle支持多种模板语言,如Bottle默认的SimpleTemplate,以及Jinja2等第三方模板引擎,用于生成动态HTML或其他格式的响应。 3. **请求和响应对象**:Bottle提供内置的Request和Response对象,...
Python套件: 瓶子0.12.16 (稳定) SQLAlchemy(with bottle-sqlalchemy) latest Jinja2 latest NPM软件包: Axios 0.18+ (AJAX调用) PostCSS / Autoprefixer 7.2+ (自动CSS前缀) Babel 7+ (将ES6代码转换为...
Flask是非常灵活的,它允许开发者快速开始一个项目,并且能够轻松地集成其他第三方库来扩展应用的功能。除了Flask之外,Python还有许多其他流行的Web框架,例如Django、Tornado、Bottle等,每个框架都有其特点和适用...
这个项目展示了如何利用Python进行Web开发,以及如何将动态数据存储和检索与轻量级Web框架相结合。 **BottlePy简介** BottlePy是一款快速、轻量级且全能的Web框架,适用于小型到中等规模的Web应用。它的核心特点...
Bottle虽然不直接提供数据库接口,但可以配合如SQLite、PostgreSQL等数据库,使用ORM(对象关系映射)库如SQLAlchemy来简化操作。 3. **验证与授权**:确保只有授权用户能发送和接收消息是安全性的基本要求。这可能...
【fbdemo:基本烧瓶服务器】是一个基于Python开发的简单Web服务器应用,它使用了微型Web框架Bottle。Bottle是一个轻量级、快速且易于使用的框架,适合开发小型到中型的Web应用程序。在深入理解fbdemo之前,我们先来...
这个项目似乎涉及了Web服务器的构建,主要使用Python语言,特别是"Bottle"框架。让我们详细探讨一下这个项目可能涵盖的知识点。 首先,**Python** 是一种高级、易读且功能丰富的编程语言,广泛应用于Web开发、数据...
"web_project:一个使用烧瓶的简单API" 这个标题表明我们正在探讨的是一个基于Web的项目,它使用了名为“烧瓶”(Bottle)的Python微型Web框架来构建一个API(应用程序编程接口)。烧瓶框架因其轻量级和易于上手的...