Skip to content
TheChatArchiveThe Chat Archive
gpt-3.5-turbo-0613· openaiHugging Face Suzhen/CodeChat

why do I get "could not locate runnable browser" from the following code:…

  1. User

    why do I get "could not locate runnable browser" from the following code: print("Confirm: " + object + "? (y/n)") object2 = input("")

    if query is incorrect program ends

    if(object2 == "y"): # asking if user wants a recent search, then printing in terminal print("Complete a recent scrape on " + object + "? (y/n)") recentSearchScrape = input("") if(recentSearchScrape == "y"): recent_year = datetime.now().year - 1 query = object + " after:" + str(recent_year)

        chrome_path="C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe"
        webbrowser.register('chrome', None,webbrowser.BackgroundBrowser(chrome_path))
        webbrowser.get('chrome').open_new_tab(url)
    
    
        url = url + str(recent_year)
        webbrowser.get(chrome_path).open(url)
    # Fetch the URL data using requests.get(url), 
    # store it in a variable, query_result
        query_result = requests.get(url) 
        soup = bs4.BeautifulSoup(query_result.text, "html.parser") 
    print(soup)
    
  2. Assistant

    The error "could not locate runnable browser" occurs because you haven't specified the path to the Chrome browser in the webbrowser.get() function.

    To fix this issue, you need to provide the full path to the Chrome browser executable file in the webbrowser.get() function. Here's an updated version of your code:

    import webbrowser
    from datetime import datetime
    
    print("Confirm: " + object + "? (y/n)")
    object2 = input("")
    
    # if query is incorrect program ends
    
    if object2 == "y":
        # asking if user wants a recent search, then printing in terminal
        print("Complete a recent scrape on " + object + "? (y/n)")
        recentSearchScrape = input("")
        
        if recentSearchScrape == "y":
            recent_year = datetime.now().year - 1
            query = object + " after:" + str(recent_year)
            
            chrome_path = "C:/Program Files (x86)/Google/Chrome/Application/chrome.exe"  # Specify the correct path here
            webbrowser.register('chrome', None, webbrowser.BackgroundBrowser(chrome_path))
            
            url = "http://example.com"  # Replace with your desired URL
            
            webbrowser.get('chrome').open_new_tab(url + str(recent_year))
            
            # Fetch the URL data using requests.get(url),
            # store it in a variable, query_result
            query_result = requests.get(url)
            soup = bs4.BeautifulSoup(query_result.text, "html.parser")
            print(soup)
    

    Make sure to replace "http://example.com" with the actual URL you want to open in the Chrome browser. Additionally, the above code assumes you have the requests and bs4 libraries imported correctly.