微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

用逗号从Web抓取时将列表元素分开

如何解决用逗号从Web抓取时将列表元素分开

我正在从网络上抓取数据,一格中有li元素,网络中的界面就是这样

 Job Description:
• Developing application programming interfaces (APIs) to support mobile functionality
• Keeping up to date with the terminology,concepts and best practices for coding mobile apps
• Using and adapting existing web applications for apps
• working closely with colleagues to constantly innovate app functionality and design

这是我针对那些部分的抓取代码的一部分,如下所示(job和jobTtle是JSON数组)

Elements ele3=doc.select("div.job-sections div[itemprop=description] section#st-jobDescription");
for (Element element3 : ele3.select("div[itemprop=responsibilities] ul")) {
     String job_description=element3.select("li").text();
     job.put(jobTitle.put(new JSONObject().put("description",job_description)));
}

这样的输出

{"description" : "Developing application programming interfaces (APIs) to support mobile functionality Keeping up to date with the terminology,concepts and best practices for coding mobile apps Using and adapting existing web applications for apps Working closely with colleagues to constantly innovate app functionality and design"}

但是我想用逗号分隔每个li元素,所以输出应该像这样

{"description" : ["Developing application programming interfaces (APIs) to support mobile functionality","Keeping up to date with the terminology,concepts and best practices for coding mobile apps","Using and adapting existing web applications for apps","Working closely with colleagues to constantly innovate app functionality and design"]}

我该如何解决?有人可以帮忙吗? 谢谢

解决方法

您需要更改存储工作职责的方式。您正在创建所需类型为JSON数组的JSON对象。

// JSON数组

f2

//在单个字符串中

Elements responsibilityElements = ele3.select("div[itemprop=responsibilities] ul li");

JSONArray responsibilities = new JSONArray();

for (Element responsibilityElement : responsibilityElements) {
     String description = responsibilityElement.text();

     responsibilities.put(description);
}

job.put("description",responsibilities);

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。