How to retreive scrapping data from web to json like format

烈酒焚心 提交于 2021-01-29 11:11:55

问题


I have try to scrape my data using jsoup and I am successfully to query all the data that I need from the web, but the problem is how to retrieve my data to json like format example of my data using cssQuery.

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

I want to format it to be like below

    {
      “<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”]
         }, 
      ],

    }

How could I solve this, I have try using gson while first construct all the element variable at the first and try to create an object and fill it with the value, but the problem the variable inside for loop so I'm confuse how do I place the created object, thanks.

*Please ignore the content, it's just the example of the output data

来源:https://stackoverflow.com/questions/64295842/how-to-retreive-scrapping-data-from-web-to-json-like-format

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!