
import os
import errno
import zipfile
import sys
import hashlib

def main():
    
    from urllib2 import Request, urlopen, HTTPError
    url_base = 'http://ethicssearch.dls.virginia.gov/ViewFormBinary.aspx?filingid='

    errors = 0
    i = 1
    while True:

        req = Request(url_base + str(i))

        try:
            f = urlopen(req)
            sys.stdout.write('.')
            sys.stdout.flush()

            errors = 0
            
            local_file = open(str(i) + '.html', 'w')
            local_file.write(f.read())
            local_file.close()

        except HTTPError as e:
            sys.stdout.write(' ')
            sys.stdout.flush()

            errors += 1

        i += 1

        if errors >= 100:
            break

if __name__ == "__main__":
    main()


import os
import errno
import zipfile
import sys
import hashlib

output_dir = 'output'

def main():

    # Make our output directory, if it doesn't exist.
    if not os.path.exists(output_dir):
        os.makedirs(output_dir)
    
    from urllib2 import Request, urlopen, HTTPError
    url_base = 'http://ethicssearch.dls.virginia.gov/ViewFormBinary.aspx?filingid='

    errors = 0
    i = 1
    while True:

        req = Request(url_base + str(i))

        try:
            f = urlopen(req)
            sys.stdout.write('.')
            sys.stdout.flush()

            errors = 0
            
            local_file = open(str(i) + '.html', 'w')
            local_file.write(f.read())
            local_file.close()

        except HTTPError as e:
            sys.stdout.write(' ')
            sys.stdout.flush()

            errors += 1

        i += 1

        if errors >= 100:
            break

if __name__ == "__main__":
    main()

Store output in a subdirectory
Store output in a subdirectory

  
  import os
  import errno
  import zipfile
  import sys
  import hashlib
  
+ output_dir = 'output'
+ 
  def main():
+ 
+     # Make our output directory, if it doesn't exist.
+     if not os.path.exists(output_dir):
+         os.makedirs(output_dir)
      
      from urllib2 import Request, urlopen, HTTPError
      url_base = 'http://ethicssearch.dls.virginia.gov/ViewFormBinary.aspx?filingid='
  
      errors = 0
      i = 1
      while True:
  
          req = Request(url_base + str(i))
  
          try:
              f = urlopen(req)
              sys.stdout.write('.')
              sys.stdout.flush()
  
              errors = 0
              
              local_file = open(str(i) + '.html', 'w')
              local_file.write(f.read())
              local_file.close()
  
          except HTTPError as e:
              sys.stdout.write(' ')
              sys.stdout.flush()
  
              errors += 1
  
          i += 1
  
          if errors >= 100:
              break
  
  if __name__ == "__main__":
      main()
  
Store output in a subdirectory
## Code Before:

import os
import errno
import zipfile
import sys
import hashlib

def main():
    
    from urllib2 import Request, urlopen, HTTPError
    url_base = 'http://ethicssearch.dls.virginia.gov/ViewFormBinary.aspx?filingid='

    errors = 0
    i = 1
    while True:

        req = Request(url_base + str(i))

        try:
            f = urlopen(req)
            sys.stdout.write('.')
            sys.stdout.flush()

            errors = 0
            
            local_file = open(str(i) + '.html', 'w')
            local_file.write(f.read())
            local_file.close()

        except HTTPError as e:
            sys.stdout.write(' ')
            sys.stdout.flush()

            errors += 1

        i += 1

        if errors >= 100:
            break

if __name__ == "__main__":
    main()

## Instruction:
Store output in a subdirectory
## Code After:

import os
import errno
import zipfile
import sys
import hashlib

output_dir = 'output'

def main():

    # Make our output directory, if it doesn't exist.
    if not os.path.exists(output_dir):
        os.makedirs(output_dir)
    
    from urllib2 import Request, urlopen, HTTPError
    url_base = 'http://ethicssearch.dls.virginia.gov/ViewFormBinary.aspx?filingid='

    errors = 0
    i = 1
    while True:

        req = Request(url_base + str(i))

        try:
            f = urlopen(req)
            sys.stdout.write('.')
            sys.stdout.flush()

            errors = 0
            
            local_file = open(str(i) + '.html', 'w')
            local_file.write(f.read())
            local_file.close()

        except HTTPError as e:
            sys.stdout.write(' ')
            sys.stdout.flush()

            errors += 1

        i += 1

        if errors >= 100:
            break

if __name__ == "__main__":
    main()
