I seem to have declared target as the input from the user. When trying to run this script with -t google.com -o test I still get the error
NameError: name 'target' is not defined
even though print('Input file is ', target) returns google.com.
What am I doing wrong?
#!usr/bin/env python3
import sys, getopt
from urllib import request
def main(argv):
   target = ''
   outputfile = ''
   try:
      opts, args = getopt.getopt(argv,"ht:o:",["target=","ofile="])
   except getopt.GetoptError:
      print('thmscraper.py -t <target address> -o <outputfile>')
      sys.exit(2)
   for opt, arg in opts:
      if opt == '-h':
         print('thmscraper.py -t <target address> -o <outputfile>')
         sys.exit()
      elif opt in ("-t", "--target"):
         target = arg
      elif opt in ("-o", "--ofile"):
         outputfile = arg
   print('Input file is ', target)
   print('Output file is ', outputfile)
if __name__ == "__main__":
   main(sys.argv[1:])
from bs4 import BeautifulSoup
html = request.urlopen(target).read().decode('utf8')
soup = BeautifulSoup(html, 'html.parser')
title = soup.find('title')
print(title)
 
    