[!] Error: Expected a '--url' parameter.

This is the place for queries that don't fit in any of the other categories.

[!] Error: Expected a '--url' parameter.

Postby xoziggieox » Fri Apr 04, 2014 5:21 am

Hello,

I have a little code to do a Google search that someone made me. It works in dos but I'd like to also use it in the Python program. I am not sure how to define the --url parameter though so that it executes properly. I was wondering what I should do to define it. I've tried url = and that didn't quite work. Here is part of the code:
Code: Select all
def main():

   parser = argparse.ArgumentParser()
   parser.add_argument("-u", "--url", help="| The URL to scrape on.")
   parser.add_argument("-n", "--num", type=int, help="| The number of results to be shown.")
   parser.add_argument("-s", "--save", type=bool, help="| If the URLs are going to be saved in a local file.")
   args = parser.parse_args()

   if args.url == None:
      print "[!] Error: Expected a \'--url\' parameter."
      sys.exit(0)
   else:
      if args.num == None:
         global num
         num = 10
      else:
         num = args.num
Last edited by Yoriz on Fri Apr 04, 2014 5:27 am, edited 1 time in total.
Reason: First post lock
xoziggieox
 
Posts: 1
Joined: Fri Apr 04, 2014 5:17 am

Re: [!] Error: Expected a '--url' parameter.

Postby Yoriz » Fri Apr 04, 2014 5:28 am

Hi, welcome to the forum, please read the 'new users read this' link in my signature if you haven't already.
New Users, Read This
Join the #python-forum IRC channel on irc.freenode.net!
Image
User avatar
Yoriz
 
Posts: 1182
Joined: Fri Feb 08, 2013 1:35 am
Location: UK

Re: [!] Error: Expected a '--url' parameter.

Postby stranac » Fri Apr 04, 2014 9:47 am

You would have to define the variables yourself instead of using argparse, which takes them from the command line(you can see exactly how it works in the linked docs).
Also, there's some yucky stuff going on in that code, like the use of globals, exiting with code 0 on error...
Friendship is magic!

R.I.P. Tracy M. You will be missed.
User avatar
stranac
 
Posts: 1246
Joined: Thu Feb 07, 2013 3:42 pm


Return to General Coding Help

Who is online

Users browsing this forum: W3C [Linkcheck] and 3 guests

cron