Larz, I was finally able to bundle lucky1.py file by removing os.py that was in the same folder from some previous coding. But the problem is that command prompt opens for a second ( I see three printed lines: Googling, url..., 200).
Does this mean that program should be better designed for user? Maybe I should first ask a question with input?
Or I have to pass sys.argv to client variable instead of test function? Now it makes more sense to me, I just don't know how to do it. :)
Does this mean that program should be better designed for user? Maybe I should first ask a question with input?
#! python3 # lucky1.py - Opens several Google search results. import webbrowser import bs4 import requests import sys client = input("Hi! Please add search term: ") def my_func(search_str): print('Googling...') # display text while downloading the Google page url = 'http://google.com/search?q=' + ' '.join(search_str) print(f'url: {url}') res = requests.get(url) print(res.status_code) # Retreive top search result links. soup = bs4.BeautifulSoup(res.text, "html.parser") # Open a browser tab for each result linkElems = soup.select('.r a') for link in linkElems: print(f'link: {link}') numOpen = min(5, len(linkElems)) for i in range(numOpen): webbrowser.open('http://google.com' + linkElems[i].get('href')) def test_it(args): print(args[1:]) my_func(args[1:]) if __name__ == '__main__': test_it(sys.argv)I added input statement but it still doesn't work after adding search term. I assume that input is taken to be sys.argv?
Or I have to pass sys.argv to client variable instead of test function? Now it makes more sense to me, I just don't know how to do it. :)