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();
}
}
jsoup读取二维码图片流并解析内容
最新推荐文章于 2021-04-29 10:40:59 发布