OpenResy+Lua 利用百度识图 将图片地址解析成文字
2024-08-27 16:07:38
LUA代码:(注:LUA里有一个调用百度识图的接口IP:123.125.115.189(stu.baidu.com),不知为什么我的虚拟机无法解析stu.baidu.com,所以我只能PING出IP来用。)
location /test {
content_by_lua ' local request_method = ngx.var.request_method;
local args = nil;
if "GET" == request_method then
args = ngx.req.get_uri_args();
else
ngx.req.read_body();
args = ngx.req.get_post_args();
end local imageUrl = args["imageUrl"] function Split(szFullString, szSeparator)
local nFindStartIndex =
local nSplitIndex =
local nSplitArray = {}
while true do
local nFindLastIndex = string.find(szFullString, szSeparator, nFindStartIndex)
if not nFindLastIndex then
nSplitArray[nSplitIndex] = string.sub(szFullString, nFindStartIndex, string.len(szFullString))
break
end
nSplitArray[nSplitIndex] = string.sub(szFullString, nFindStartIndex, nFindLastIndex - )
nFindStartIndex = nFindLastIndex + string.len(szSeparator)
nSplitIndex = nSplitIndex +
end
return nSplitArray
end local cjson = require "cjson"
local http = require "resty.http"
local hc = http:new() local ok, code, headers, status, body = hc:request {
url = "http://123.125.115.189/n/pc_search?queryImageUrl="..imageUrl,
method = "GET", -- POST or GET
} local _,aaa = string.find(body,"keywords:\'")
local bbb = string.find(body,"|default")
local ccc = string.sub(body,aaa+,bbb-)
ngx.say(tostring(ccc))
';
}
HTML代码:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<title>Untitled</title>
<script src="http://libs.baidu.com/jquery/1.7.2/jquery.min.js"></script>
</head> <body> <input type="button" value = "test" id ="test" />
<input type="text" id ="imgUrl" />
<input type="button" value = "识图" id ="st" /> </body> <script> function unicode2Chr(str) {
str=str.replace(/\\/g,"%");
return unescape(str); } $(function(){
$("#test").click(function(){
alert();
var str = "\x22\\u82f9\\u679c\x22,\x22\\u6307\\u6325\\u5927\\u5e08\x22,\x22\\u51fa\\u67dc\x22";
var code = str.replace(/\x22/g, "")
alert(code);
alert(unicode2Chr(code));
}); $("#st").click(function(){ var image_Url = $("#imgUrl").val(); $.ajax({
type : "POSST",
async : false,
url : "/test",
data:{imageUrl:image_Url},
success : function(data) {
var code = data.replace(/\\x22/g, "")
alert(unicode2Chr(code).replace(/%/g, ""));
}
});
}); }); </script>
</html>
最新文章
- FilenameFilter过滤文件名
- Java---类加载机制,构造方法,静态变量,(静态)代码块,父类,变量加载顺序
- servlet 学习(一)
- 微信公开课(北京站)速记 微信、微信支付、O2O的定义与关联
- Android 使用 TableLayout 布局拉伸宽度
- web运维第一篇:nginx配置文件详解笔记
- java equals 心得体会
- 对比Windows 8模拟器(Simulator)和Windows Phone仿真器(Emulator)
- 分享基于分布式Http长连接框架--设计模型
- java常用字节流
- Perl进程:僵尸进程和孤儿进程
- kafka快速开始
- 调用 Webapi 跨域
- 利用crontab每天定时备份MySQL数据库
- 【codeforces 528D】 Fuzzy Search
- UGUI 事件穿透规则
- 分享几个IP获取地理位置的API接口(最全面的了)
- python命名空间的本质
- window.location和window.open的区别
- PAT——1008. 数组元素循环右移问题
热门文章
- mysql的事务处理
- CLR via C#(13)-浅谈事件
- oracle数据库出现“批处理中出现错误: ORA-00001: 违反唯一约束条件”解决方法
- Delphi中DLL的创建和使用
- Pyqt QSplashScreen启动画面
- 【JAVA与DOM4J实现对XML文档的CRUD操作】
- 攻城狮在路上(贰) Spring(二)--- Spring IoC概念介绍
- 使用nbrbutil工具來處理requested media id is in use, cannot process request
- ASP.NET WebApi Document Helper
- wp8 入门到精通 虚拟标示符 设备ID