I have a list of keywords stored in a column in an Excel sheet. I want to do a Google search for each keyword in separate chrome tabs.
Can anyone please help me with Python code to automate it?
I have a list of keywords stored in a column in an Excel sheet. I want to do a Google search for each keyword in separate chrome tabs.
Can anyone please help me with Python code to automate it?
Rahil, say your keywords are in the "A" column of rahils_keywords.xlsx file, in the worksheet called keywords. At the shell, install this dependency:
> pip install openpyxl
Then in your text editor or Python REPL:
import webbrowser
from openpyxl import load_workbook
def google_search_keywords_from_spreadsheet(path: str, sheet: str, column: str):
    wb = load_workbook(filename=path)
    worksheet = wb[sheet]
    num_rows = worksheet.max_row
    for row_num in range(num_rows):
        cell = f"{column}{row_num + 1}"
        keyword = worksheet[cell].value
        if keyword: # skip blank cells
            url = f"https://google.com/search?q={keyword}"
            print(f'searching for keyword "{keyword}"...')
            webbrowser.open(url)
google_search_keywords_from_spreadsheet(
    path="rahils_keywords.xlsx",
    sheet="keywords",
    column="A",
)