title: I want to Save Maps in JSON File from Selenium Scrape data
body: <p>I scraped a website and I get all the data from it and I want store it in json file
  so I could use it as an API the problem is that when it tries to write  maps in JSON file it get duplicated because I called json.dumps inside for loop this is what I try to do</p>
  <p>How can I append to chapters list and keep the title the same I have more books also it gonna be a list</p>
  <pre><code>{
    &quot;title&quot;:&quot;Kingdom&quot;,
     &quot;chapters&quot;:[
      {
        &quot;chapter-title&quot;: &quot;Kingdom - 12&quot;,
        &quot;images&quot; : [
          &quot;image1.jpg&quot;,
          &quot;image2.jpg&quot;,
          &quot;image3.jpg&quot;
        ]
      }{
        &quot;chapter-title&quot;: &quot;Kingdom - 13&quot;,
        &quot;images&quot; : [
          &quot;image1.jpg&quot;,
          &quot;image2.jpg&quot;,
          &quot;image3.jpg&quot;
        ]
      }{
        &quot;chapter-title&quot;: &quot;Kingdom - 14&quot;,
        &quot;images&quot; : [
          &quot;image1.jpg&quot;,
          &quot;image2.jpg&quot;,
          &quot;image3.jpg&quot;
        ]
      }{
        &quot;chapter-title&quot;: &quot;Kingdom - 15&quot;,
        &quot;images&quot; : [
          &quot;image1.jpg&quot;,
          &quot;image2.jpg&quot;,
          &quot;image3.jpg&quot;
        ]
      }
    ]
  }
  </code></pre>
  <p>and this is what I got :</p>
  <pre><code>{
    &quot;title&quot;:&quot;Kingdom&quot;,
     &quot;chapters&quot;:[
      {
        &quot;chapter-title&quot;: &quot;Kingdom - 12&quot;,
        &quot;images&quot; : [
          &quot;image1.jpg&quot;,
          &quot;image2.jpg&quot;,
          &quot;image3.jpg&quot;
        ]
      }
    ]
  }{
    &quot;title&quot;:&quot;Kingdom&quot;,
     &quot;chapters&quot;:[
      {
        &quot;chapter-title&quot;: &quot;Kingdom - 13&quot;,
        &quot;images&quot; : [
          &quot;image1.jpg&quot;,
          &quot;image2.jpg&quot;,
          &quot;image3.jpg&quot;
        ]
      }
    ]
  }{
    &quot;title&quot;:&quot;Kingdom&quot;,
     &quot;chapters&quot;:[
      {
        &quot;chapter-title&quot;: &quot;Kingdom - 14&quot;,
        &quot;images&quot; : [
          &quot;image1.jpg&quot;,
          &quot;image2.jpg&quot;,
          &quot;image3.jpg&quot;
        ]
      }
    ]
  }
  </code></pre>
  <pre><code>def getAllImages(url=&quot;&quot;):
      chrome_options = Options()
      chrome_options.add_argument(&quot;--headless&quot;)
  
      driver = webdriver.Chrome(chrome_options=chrome_options)
  
      try:
          driver.get(url)
          driver.implicitly_wait(2)
      except Exception as e:
          print(&quot;Error Getting Images Page :&quot;, e)
  
      print(driver.title)
  
      divs = driver.find_elements_by_class_name(&quot;page-break &quot;)
  
      images = []
      for div in divs:
          image = div.find_elements_by_tag_name(&quot;img&quot;)
  
          [images.append(j.get_attribute(&quot;src&quot;).strip()) for j in image]
  
      chapters ={&quot;chapter-title&quot;: driver.title, &quot;images&quot;: images}
  
      list = [{&quot;title&quot;:&quot;Kingdom&quot;,&quot;chapters&quot;:[]}]
      list[0][&quot;chapters&quot;].append(chapters)
      
      toJson = json.dumps(list, ensure_ascii=False, indent=2)
      with open(&quot;./&quot; + &quot;manga.json&quot;, &quot;r+&quot;) as f:
          if len(f.read()) == 0:
              f.write(toJson)
          else:
              f.write(&quot;,\n&quot; + toJson)
  
      print(&quot;Successfully created &quot;)
  
  for url in links:
      getAllImages(url)
  </code></pre>