jsoup读取二维码图片流并解析内容

public static void main(String[] args) {
        String[] ips = new String[]{"35.220.130.255", "81"};
        String agent = Agent.getRandom();
        Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(ips[0], Integer.parseInt(ips[1])));
        try {
            String sourceUrl = "http://esf.whfgxx.org.cn/New/pub/Clf_QRcode/kneSeI4NVjfYS6U8ApzZQ6dSv6wfGE9nYR61";
            Connection connection = Jsoup.connect(sourceUrl).followRedirects(true).ignoreContentType(true)
                    .proxy(proxy).timeout(10000);
            connection.header("Host", "esf.whfgxx.org.cn");
            connection.header("User-Agent", agent);
            connection.header("Origin", "http://esf.whfgxx.org.cn");
            connection.header("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9");
            Connection.Response execute = connection.referrer("http://esf.whfgxx.org.cn").execute();
            byte[] bytes = execute.bodyAsBytes();
            InputStream sbs = new ByteArrayInputStream(bytes);
            BufferedImage image = ImageIO.read(sbs);
            Binarizer binarizer = new HybridBinarizer(new BufferedImageLuminanceSource(image));
            BinaryBitmap binaryBitmap = new BinaryBitmap(binarizer);
            MultiFormatReader read = new MultiFormatReader();
            Result res = read.decode(binaryBitmap);
            // http://esf.whfgxx.org.cn/New/pub/FangyView/kneSeI4NVjfYS6U8ApzZQ6dSv6wfGE9nYR61?refer=&corp=&org=
            System.err.println(res.toString());

            //String pic = "http://esf.whfgxx.org.cn/new/html/Fang/kneSeI4NVjfYS6U8ApzZQ6dSv6wfGE9nYR61/202009103.html?refer=&corp=&org=";
            Connection connection1 = Jsoup.connect(res.toString()).followRedirects(false).ignoreContentType(true)
                    .proxy(proxy).timeout(10000)
                    .header("Host", "esf.whfgxx.org.cn")
                    .header("Upgrade-Insecure-Requests", "1")
                    .header("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8")
                    .header("User-Agent", "Mozilla/5.0 (iPhone; CPU iPhone OS 13_6_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 MicroMessenger/7.0.15(0x17000f2b) NetType/4G Language/zh_CN")
                    .header("Accept-Language", "zh-cn")
                    .header("Accept-Encoding", "gzip, deflate")
                    .header("Connection", "keep-alive");
            Document document = connection1.get();
            String href = document.select("a").attr("href");

            String url = "http://esf.whfgxx.org.cn" + href;

            Connection connection2 = Jsoup.connect(url).followRedirects(true).ignoreContentType(true)
                    .proxy(proxy).timeout(10000);
            connection2.header("Host", "esf.whfgxx.org.cn");
            connection2.header("User-Agent", agent);
            connection2.header("Origin", "http://esf.whfgxx.org.cn");
            connection2.header("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9");
            Document document1 = connection2.get();
            String select = document1.select(".s1.i.g").text();
            System.err.println(select);
        } catch (Exception e) {
            //更换ip重试 一直到获取到String select = document1.select(".s1.i.g").text(); 的值 。最大10次
            e.printStackTrace();
        }
    }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值