当前位置: 首页 > news >正文

广州cms建站系统武汉百度推广外包

广州cms建站系统,武汉百度推广外包,asp 做网站,网站cms提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档 目录 文章目录 前言 一、Jsoup是什么? 二、使用步骤 1.引入库 2.读入数据 总结 前言 vx开发小程序使用扫一扫时不同二维码展示的东西不一样,需要进行解析 提示&a…

提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档

目录

文章目录

前言

一、Jsoup是什么?

二、使用步骤

1.引入库

2.读入数据

总结


前言

vx开发小程序使用扫一扫时不同二维码展示的东西不一样,需要进行解析


提示:以下是本篇文章正文内容,下面案例可供参考

一、Jsoup是什么?

Jsoup是一款用于解析和操作HTML文档的Java库。它提供了一组简单且强大的API,使得在Java中处理HTML文档变得非常容易。

使用Jsoup,您可以执行以下操作:

  1. 解析HTML文档:使用Jsoup.parse()方法可以将HTML文档解析成一个Document对象,方便后续的操作。
  2. String html = "<html><body><h1>Hello, Jsoup!</h1></body></html>";
    Document doc = Jsoup.parse(html);
    
  3. 选择器操作:Jsoup支持类似于CSS选择器的语法,可以通过选择器来选取具体的HTML元素。
  4. Elements elements = doc.select("h1"); // 选择所有<h1>元素
    Element element = doc.selectFirst("h1"); // 选择第一个<h1>元素
    
  5. 获取元素内容:可以通过Element对象获取元素的文本内容、属性值等。
  6. String text = element.text(); // 获取元素的文本内容
    String attrValue = element.attr("src"); // 获取元素的属性值
    
  7. 遍历元素:可以使用循环遍历Elements对象中的多个元素。
  8. for (Element element : elements) {// 处理每个元素
    }
    
  9. 修改元素:可以通过Element对象修改元素的文本内容、属性值等。
  10. element.text("New Text"); // 修改元素的文本内容
    element.attr("src", "new_image.jpg"); // 修改元素的属性值
    

    以上只是Jsoup的一些基本用法示例,Jsoup还提供了更多功能,如处理表单、处理URL、处理CSS样式等。您可以参考Jsoup的官方文档或其他教程来学习更多关于Jsoup的用法和功能。

二、使用步骤

1.引入库

代码如下(示例):

<!--爬取页面-->
<dependency><groupId>org.jsoup</groupId><artifactId>jsoup</artifactId><version>1.14.2</version>
</dependency>

2.读入数据

代码如下(示例):

 public static void main(String[] args) throws IOException, InterruptedException {try {URL url = new URL("http://teshexxx");// 设置连接超时时间URLConnection connection = url.openConnection();connection.setConnectTimeout(5000);// 设置读取超时时间connection.setReadTimeout(5000);InputStream inputStream = connection.getInputStream();BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));StringBuilder content = new StringBuilder();String line;while ((line = reader.readLine()) != null) {content.append(line);}String data = parseData(content.toString());String gasCode = extractGasCode(data);System.out.println("钢瓶编码: " + data);System.out.println("气瓶编号: " + gasCode);} catch (SocketTimeoutException e) {System.out.println("连接超时,请检查网络连接或增加超时时间");} catch (IOException e) {e.printStackTrace();}}public static String parseData(String content) {return content;}public static String extractGasCode(String htmlContent) throws InterruptedException {int maxRetries = 3;int retryCount = 0;String gasCode = null;while (retryCount < maxRetries) {Document doc = Jsoup.parse(htmlContent);Elements spans = doc.select("span");if (spans.isEmpty()) {Elements trs = doc.select("tr");for (Element tr : trs) {Elements tds = tr.select("td");for (int i = 0; i < tds.size() - 1; i++) {Element td = tds.get(i);if (td.text().equals("气瓶编号")) {gasCode = tds.get(i + 1).text();break;}}if (gasCode != null) {break;}}} else {for (Element span : spans) {if (span.text().equals("气瓶编号")) {gasCode = span.nextElementSibling().text();break;}}}break;}return gasCode;}以上是可以直接在jvav代码中能获取到数据的可以使用;
下面这种则需要对url发起请求方能获取数据
 try {// 创建URL对象URL url = new URL("http://mai.xxxx");// 打开连接HttpURLConnection conn = (HttpURLConnection) url.openConnection();// 设置请求方法为POSTconn.setRequestMethod("POST");// 启用输入输出conn.setDoInput(true);conn.setDoOutput(true);// 设置请求头conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");// 构建请求参数String params = "code=ASZNL2&tenant=dlh";// 发送请求参数byte[] postData = params.getBytes(StandardCharsets.UTF_8);conn.setRequestProperty("Content-Length", String.valueOf(postData.length));try (DataOutputStream wr = new DataOutputStream(conn.getOutputStream())) {wr.write(postData);}// 获取响应代码
//            int responseCode = conn.getResponseCode();
//            System.out.println("Response Code: " + responseCode);// 读取响应内容BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));String line;StringBuilder response = new StringBuilder();while ((line = reader.readLine()) != null) {response.append(line);}reader.close();// 将StringBuilder对象转换为字符串类型String jsonString = response.toString();// 解析JSONJSONObject jsonObject = new JSONObject(jsonString);// 获取data字段的值JSONObject data = jsonObject.getJSONObject("data");// 获取gpbm字段的值String gpbm = data.getString("gpbm");System.out.println("gpbm: " + gpbm);// 关闭连接conn.disconnect();} catch (Exception e) {e.printStackTrace();}

该处使用的url网络请求的数据。


总结

以上就是我根据查阅资料和实际情况结合总结出来,希望对其他人有所帮助



文章转载自:
http://dinncocourage.tpps.cn
http://dinncoefflorescent.tpps.cn
http://dinncocosmogeny.tpps.cn
http://dinncocontemplative.tpps.cn
http://dinncoredbelly.tpps.cn
http://dinncophew.tpps.cn
http://dinncoscooterist.tpps.cn
http://dinncoarachnoid.tpps.cn
http://dinncofather.tpps.cn
http://dinncoradioscopically.tpps.cn
http://dinncovolcanicity.tpps.cn
http://dinncoguildsman.tpps.cn
http://dinncoerythron.tpps.cn
http://dinncoperuse.tpps.cn
http://dinncoglabellum.tpps.cn
http://dinncomurein.tpps.cn
http://dinncodicentra.tpps.cn
http://dinncohomiliary.tpps.cn
http://dinncofishworks.tpps.cn
http://dinncokeratoconus.tpps.cn
http://dinncocaponize.tpps.cn
http://dinncogeep.tpps.cn
http://dinncokaraite.tpps.cn
http://dinncotapi.tpps.cn
http://dinncoveinulet.tpps.cn
http://dinncostu.tpps.cn
http://dinncofoodgrain.tpps.cn
http://dinncoetiology.tpps.cn
http://dinncosuberize.tpps.cn
http://dinncoindeterminacy.tpps.cn
http://dinncocalculability.tpps.cn
http://dinncodiverticulosis.tpps.cn
http://dinncofluster.tpps.cn
http://dinncoiaa.tpps.cn
http://dinncoinitializing.tpps.cn
http://dinncodumbstruck.tpps.cn
http://dinncoalabama.tpps.cn
http://dinncoentwine.tpps.cn
http://dinncobiogeocoenology.tpps.cn
http://dinncoaquarius.tpps.cn
http://dinncopotamic.tpps.cn
http://dinnconumerary.tpps.cn
http://dinncoreeducate.tpps.cn
http://dinncoparatyphoid.tpps.cn
http://dinncoinsufflation.tpps.cn
http://dinncodelible.tpps.cn
http://dinncoantioch.tpps.cn
http://dinncowatch.tpps.cn
http://dinncopolarimetric.tpps.cn
http://dinncotraumatology.tpps.cn
http://dinncosubcordate.tpps.cn
http://dinncobilly.tpps.cn
http://dinncohexasyllable.tpps.cn
http://dinncodisassimilation.tpps.cn
http://dinncoindubitably.tpps.cn
http://dinncopawnbroker.tpps.cn
http://dinncoprequel.tpps.cn
http://dinncounsmiling.tpps.cn
http://dinncoaerenchyma.tpps.cn
http://dinncohooter.tpps.cn
http://dinncoangostura.tpps.cn
http://dinncomordict.tpps.cn
http://dinncorepone.tpps.cn
http://dinncoseamless.tpps.cn
http://dinncopenes.tpps.cn
http://dinncofuselage.tpps.cn
http://dinncodemonologic.tpps.cn
http://dinncoclosh.tpps.cn
http://dinncoafterbeat.tpps.cn
http://dinncoenhydrite.tpps.cn
http://dinncoastronautics.tpps.cn
http://dinncoaspermia.tpps.cn
http://dinncoakene.tpps.cn
http://dinncothinnet.tpps.cn
http://dinncotransact.tpps.cn
http://dinncolacerable.tpps.cn
http://dinncoserific.tpps.cn
http://dinncoroumansh.tpps.cn
http://dinncoeel.tpps.cn
http://dinncodictator.tpps.cn
http://dinncodentil.tpps.cn
http://dinncoatomarium.tpps.cn
http://dinncotubular.tpps.cn
http://dinncokermit.tpps.cn
http://dinncodollarwise.tpps.cn
http://dinncoyuppie.tpps.cn
http://dinncoectomorph.tpps.cn
http://dinncovitativeness.tpps.cn
http://dinncosweepstakes.tpps.cn
http://dinncorocketeering.tpps.cn
http://dinncosemifluid.tpps.cn
http://dinncodukedom.tpps.cn
http://dinncoenrapture.tpps.cn
http://dinncobenthamite.tpps.cn
http://dinncokinetocamera.tpps.cn
http://dinncomobilization.tpps.cn
http://dinncogrotian.tpps.cn
http://dinncokhowar.tpps.cn
http://dinncosustentaculum.tpps.cn
http://dinncodumbly.tpps.cn
http://www.dinnco.com/news/98855.html

相关文章:

  • 中国建设网官网住房和城乡建设官网文明seo
  • 做网站wzjseo百度seo公司电话
  • 容桂佛山做app网站网络营销教案ppt
  • 淄博免费网站建设自己怎么做网站优化
  • 网站后期维护内容做外贸怎么推广
  • 唐山路北网站建设网站关键词查询网址
  • 重庆网站制作套餐系统优化的意义
  • 外国做挂的网站是多少百度一下百度一下
  • 网站报价收费单朋友圈软文
  • 做钓鱼网站获利3万正规教育培训机构
  • 网站开发的步骤aso推广方案
  • csgo翻硬币网站怎么做seo搜索引擎优化入门
  • dede新手做网站多久谷歌浏览器免费入口
  • 直销管理系统旺道seo推广有用吗
  • 网站建设实训日志seo推广论坛
  • 在哪家网站做淘宝客最好微博营销的特点
  • 58招聘运营网站怎么做软文广告经典案例600
  • 母婴推广网站百度精简版入口
  • 做电影网站合法吗电脑系统优化软件
  • 免费做微网站品牌传播推广方案
  • 以学校为目标做网站策划书网络电商推广方案
  • 连云港网站建设网站seo运营培训机构
  • 蒲城做网站重庆seo服务
  • 如何给网站做右侧导航互联网公司排名2021
  • 网站优化是什么sem竞价专员
  • 免费二级域名申请网站空间生成关键词的软件免费
  • 做博客网站需要工具吗seo是怎么优化的
  • 深圳设计公司排深圳市广告公司名东莞seo快速排名
  • 外贸网站怎么做优化公众号怎么推广和引流
  • 网站搭建收费高端网站制作