zoukankan      html  css  js  c++  java
  • 京东商城(360Buy)价格识别 java版

    上一篇介绍到 利用Jsoup抓取各个电商网站的信息

    不过有时候会遇到价格是图片的问题

    这时候你只能得到一张图片了

    如果有个能把图片解析出来那该多爽啊

    去百度一搜“京东(360Buy)价格识别”  还真有

    猪八戒上有人还发布任务了,不过那都是老早以前的了

    网上有好多版本,

    我自己也做了一个java版的

    识别率 99.9%

    我们相信java的强大,不过怕涉及到侵权问题,源码我就不贴了 需要学习的可以留邮箱,我发给你

    这里我只讲思路

    (1)首先你的会切图 用java

       下面给个小例子:

       这个是个切图的方法,x,y 是原来图片要切割的起始坐标, wight 和hight 是 要切割的宽和高, img 是原图的流

       这是一个队Png 后缀的图的切割方法,也是后一个抠图的方法,

      如果想切割jpg 的 的话,可以把两句改改

    =============

    BufferedImage.TYPE_INT_RGB

    PNG

    ================

    BufferedImage newImage = new BufferedImage(wight, hight,  BufferedImage.TYPE_INT_ARGB);
     ImageIO.write(newImage, "PNG", new File(x + "_" + y + "_" + wight
                       
    + "_.png"));

    public static BufferedImage cat(int x, int y, int wight, int hight,
                BufferedImage img) {
            int[] simgRgb = new int[wight * hight];
            img.getRGB(x, y, wight, hight, simgRgb, 0, wight);
            BufferedImage newImage = new BufferedImage(wight, hight,
                    BufferedImage.TYPE_INT_ARGB);
            newImage.setRGB(0, 0, wight, hight, simgRgb, 0, wight);
            try {
                ImageIO.write(newImage, "PNG", new File(x + "_" + y + "_" + wight
                        + "_.png"));
            } catch (IOException e) {
                e.printStackTrace();
            }
            return newImage;
        }

     (2)会对图片做索引

       对图片做索引我前面讲过了

     (3) 将网上抓来的价格图片切割后在你的索引里查询,

    (4) 将返回的第一个字记录下来

    最后输出结果 下面是我贴的部分结果:

    ps:由于京东价格在不断变化的,这个例子已经失效了,上面的图片地址有的已经不存在了,程序修改了下,还是可以用的

    http://price.360buyimg.com/gp1005187106,1.png
    图片链接错误,请查证!!!!
    http://price.360buyimg.com/gp1006754125,1.png
    144.00
    http://price.360buyimg.com/gp635281,1.png
    348.00
    http://price.360buyimg.com/gp1006749154,1.png
    229.00
    http://price.360buyimg.com/gp1002462797,1.png
    图片链接错误,请查证!!!!
    http://price.360buyimg.com/gp1003198953,1.png
    168.00
    http://price.360buyimg.com/gp247723,1.png
    图片链接错误,请查证!!!!
    http://price.360buyimg.com/gp1005973369,1.png
    220.00
    http://price.360buyimg.com/gp1005258226,1.png
    175.00
    http://price.360buyimg.com/gp635260,1.png
    318.00
    http://price.360buyimg.com/gp412666,1.png
    64.00
    http://price.360buyimg.com/gp1006702266,1.png
    229.00
    http://price.360buyimg.com/gp1005973327,1.png
    220.00
    http://price.360buyimg.com/gp623242,1.png
    67.00
    http://price.360buyimg.com/gp623244,1.png
    191.00
    http://price.360buyimg.com/gp333428,1.png
    318.00
    http://price.360buyimg.com/gp285159,1.png
    266.00
    http://price.360buyimg.com/gp1005186888,1.png
    图片链接错误,请查证!!!!
    http://price.360buyimg.com/gp412669,1.png
    175.00
    http://price.360buyimg.com/gp623246,1.png
    195.00
    http://price.360buyimg.com/gp247729,1.png
    图片链接错误,请查证!!!!
    http://price.360buyimg.com/gp252585,1.png
    66.00
    http://price.360buyimg.com/gp252586,1.png
    178.00
    http://price.360buyimg.com/gp668124,1.png
    63.00
    http://price.360buyimg.com/gp668119,1.png
    174.00
    http://price.360buyimg.com/gp412663,1.png
    179.00
    http://price.360buyimg.com/gp300728,1.png
    83.80
    http://price.360buyimg.com/gp623208,1.png
    104.00
    http://price.360buyimg.com/gp300731,1.png
    208.00
    http://price.360buyimg.com/gp344861,1.png

     测试结果太给力了,99.9999999999999%的准确性

     由于好多人问我要,我也不经常上博客,留下下载地址

     下载点这里

  • 相关阅读:
    Python 使用gevent下载图片案例
    Python 使用gevent实现多任务
    Python 生成器
    Python 自己实现可迭代对象
    Python 遍历文件夹清理磁盘案例
    Python 多进程拷贝文件夹案例
    Python 多进程编程
    Python 多线程编程
    Python TCP通信之仿文件下载
    Python UDP 通信
  • 原文地址:https://www.cnblogs.com/tomcattd/p/2844017.html
Copyright © 2011-2022 走看看