京東商城(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%的准確性

 由於好多人問我要,我也不經常上博客,留下下載地址

 下載點這里

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM