code: def download_from_search(query_str, folder, do_extract_text=True,
                           max_results=None):
      
      piis = get_piis(query_str)
      for pii in piis[:max_results]:
          if os.path.exists(os.path.join(folder, '%s.txt' % pii)):
              continue
          logger.info('Downloading %s' % pii)
          xml = download_article(pii, 'pii')
          sleep(1)
          if do_extract_text:
              txt = extract_text(xml)
              if not txt:
                  continue
  
              with open(os.path.join(folder, '%s.txt' % pii), 'wb') as fh:
                  fh.write(txt.encode('utf-8'))
          else:
              with open(os.path.join(folder, '%s.xml' % pii), 'wb') as fh:
                  fh.write(xml.encode('utf-8'))
      return
docs: Save raw text files based on a search for papers on ScienceDirect.
  
      This performs a search to get PIIs, downloads the XML corresponding to
      the PII, extracts the raw text and then saves the text into a file
      in the designated folder.
  
      Parameters
      ----------
      query_str : str
          The query string to search with
      folder : str
          The local path to an existing folder in which the text files
          will be dumped
      do_extract_text : bool
          Choose whether to extract text from the xml, or simply save the raw xml
          files. Default is True, so text is extracted.
      max_results : int or None
          Default is None. If specified, limit the number of results to the given
          maximum.