如何将数据从Web检索到JSON之类的格式

时间:2020-10-10 16:41:25

标签: java html css web-scraping jsoup

我已经尝试使用jsoup抓取数据,并且可以成功从Web查询我需要的所有数据,但是问题是如何使用cssQuery将数据检索到json之类的数据格式示例。

Faculty of Engineering
Computer Science
Washington
Understanding algorithm and data structures Implement to solve real problem Good understanding how computer work

Mechanical Engineering
New York
Understand how machine works Can implement the theory to solve real problem  

Faculty of Science
Mathematics
Toronto
Understand a fundamental concept of Algebra Can Implement the theory to solve real problem Understand number theory

Physics
Chicago
Understand how universe work Understand how to implement the concept to solve real problem Understand fundamental law of physics

我想将其格式化为以下格式

    {
      “<Faculty  name>”: [
        {  “major”: “<major name>”,
          “location”: “<location>”,
          “expected output”: [“<expected output>”, “<expected output>”, “<expected output>”],
         }, 
      ]
    }

    {
      “Faculty  of Engineering”: [
        {  “major”: “Computer Science”,
          “location”: “Washington”,
          “expected output”: [“Understanding algorithm and data structures”, “Implement to solve real problem”, “Good understanding how computer work”],
         }, 
        {  “major”: “Mechanical Egineering”,
          “location”: “New York”,
          “expected output”: [“Understand how machine works”, “Can implement the theory to solve real problem”]
         }, 
      ],
      “Faculty of Science”: [
        {  “major”: “Mathematics”,
          “location”: “Toronto,
          “expected output”: [“Understand the fundamental concept of Algebra”, “Can Implement the theory to solve real problem”, “Understand number theory”],
         }, 
        {  “major”: “Physics”,
          “location”: “Chicago”,
          “expected output”: [“Understand how universe work”, “Understand how to implement the concept to solve real problem”, “Understand fundamental law of physics”]
         }, 
      ],

    }

我该如何解决这个问题,我先尝试使用gson,同时首先构造了所有元素变量,然后尝试创建一个对象并用值填充它,但是问题在于for循环内的变量,因此我感到困惑我如何放置创建的对象,谢谢。

*请忽略内容,这只是输出数据的示例

0 个答案:

没有答案
相关问题