open multiple tabs using selenium I am using the following script to read search terms from a file and then search those terms in google (each search result in it's own tab).
from selenium import webdriver

browser = webdriver.Chrome()

# first tab
browser.get('https://google.com')

with open(&quot;google-search-terms.adoc&quot;) as fin:
    for line_no, line in enumerate(fin):
        line = line.strip()
        line = line.replace(' ', '+')
        line = line.replace('&amp;', '%26')
        browser.execute_script(
            &quot;window.open('https://www.google.com/search?q=&quot;+line+&quot;');&quot;)

How can I make this code better?
Functions
Create individual smaller functions doing a single task.
Enumerations
The enumeration for file does not make sense. line_no servers no purpose.
if __name__ block
For scripts, it is a good practice to put your executable feature inside the if __name__ == &quot;__main__&quot; clause.
A rewrite of the same code might look like:
from selenium import webdriver

FILE_NAME = &quot;google-search-terms.adoc&quot;

def search_google(browser, term: str):
    term = term.replace(' ', '+').replace('&amp;', '%26')
    browser.execute_script(f&quot;window.open('https://www.google.com/search?q={term}');&quot;)


def process_file(filename: str) -&gt; str:
    with open(filename) as fin:
        for line in fin:
            yield line.strip()


def main():
    browser = webdriver.Chrome()
    browser.get('https://google.com')
    for search_term in process_file(FILE_NAME):
        search_google(browser, search_term)


if __name__ == &quot;__main__&quot;:
    main()