File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11#! /usr/bin/env python3
22
3- import sys , webbrowser
3+ """Script to search with Google
44
5- def main ():
6- args = sys .argv [1 :]
7- if not args :
8- print ("Usage: %s querystring" % sys .argv [0 ])
9- return
10- list = []
11- for arg in args :
12- if '+' in arg :
13- arg = arg .replace ('+' , '%2B' )
5+ Usage:
6+ python3 google.py [search terms]
7+ """
8+
9+ import sys
10+ import urllib .parse
11+ import webbrowser
12+
13+
14+ def main (args ):
15+ def quote (arg ):
1416 if ' ' in arg :
1517 arg = '"%s"' % arg
16- arg = arg . replace ( ' ' , '+' )
17- list . append ( arg )
18- s = '+' .join (list )
19- url = "http ://www.google.com/search?q=%s" % s
18+ return urllib . parse . quote_plus ( arg )
19+
20+ qstring = '+' .join (quote ( arg ) for arg in args )
21+ url = urllib . parse . urljoin ( 'https ://www.google.com/search' , ' ?q=' + qstring )
2022 webbrowser .open (url )
2123
2224if __name__ == '__main__' :
23- main ()
25+ main (sys . argv [ 1 :] )
You can’t perform that action at this time.
0 commit comments