Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/401.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 使用逗号从web上刮取时分离列表元素_Java_Json_Web Scraping_Jsoup_Org.json - Fatal编程技术网

Java 使用逗号从web上刮取时分离列表元素

Java 使用逗号从web上刮取时分离列表元素,java,json,web-scraping,jsoup,org.json,Java,Json,Web Scraping,Jsoup,Org.json,我正在从web上抓取数据,在一个div中有li元素,web中的界面如下 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 ada

我正在从web上抓取数据,在一个div中有li元素,web中的界面如下

 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
{"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"}
{"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数组)

输出是这样的

 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
{"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"}
{"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元素,所以输出应该是这样的

 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
{"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"}
{"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数组

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)));
}
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);

//一串

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

List<String> lines = new ArrayList<>();

for (Element responsibilityElement : responsibilityElements) {
    lines.add(responsibilityElement.text());
}

String description = String.join(", ", lines);
job.put("description", description);
Elements responsibilityElements=doc.select(“ul li”);
//元素责任元素=元素3.选择(“div[itemprop=responsibility]ul li”);
列表行=新的ArrayList();
对于(要素责任要素:责任要素){
add(responsibilitylement.text());
}
String description=String.join(“,”行);
作业。放置(“说明”,说明);

hmm明白你的意思,但问题是我不能用逗号分隔
  • 元素,当我存储它时,输出显示一行所有
  • 元素,我想用逗号分隔,怎么做?@aarons你预期的输出格式不清楚,在您提出的问题中,您希望在JSON数组中包含
    li
    s的内容,请提供一个示例输出,以便我可以提供帮助。感谢您的帮助,我的预期代码输出在以下句子“输出如下”下,但我的预期输出在以下句子下“但是我想用逗号分隔每个li元素,所以输出应该是这样的。”我认为这很清楚。