'How to convert Python + Selenium to .EXE?

import time
import os
import sys
import pandas as pd
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.options import Options

def resource_path(another_way):
    try:
        usual_way = sys._MEIPASS  # When in .exe, this code is executed, that enters temporary directory that is created automatically during runtime.
    except Exception:
        usual_way = os.path.dirname(__file__)  # When the code in run from python console, it runs through this exception.
    return os.path.join(usual_way, another_way)


op = Options()
op.headless = True
SCROLL_PAUSE_TIME = 2

driver = webdriver.Chrome(resource_path('chromedriver.exe'), options=op)
get = input('Ссылку: ')
file = input('Имя файла: ')
driver.get(get)
time.sleep(5)
last_height = driver.execute_script("return document.body.scrollHeight")
driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
time.sleep(1)
driver.find_element(By.XPATH, '/html/body/div[7]/div/div[2]/div/div[2]/div/div/div[2]/div/div/div[4]/a[2]').click()
while True:
    # Scroll down to bottom
    driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")

    # Wait to load page
    time.sleep(SCROLL_PAUSE_TIME)

    # Calculate new scroll height and compare with last scroll height
    new_height = driver.execute_script("return document.body.scrollHeight")
    if new_height == last_height:
        break
    last_height = new_height

time.sleep(10)
namee = []
pricee = []
imagee = []

for name in driver.find_elements(By.CLASS_NAME, 'market_row_name'):
    namee.append(name.text)

for price in driver.find_elements(By.CLASS_NAME, 'market-item-price'):
    pricee.append(price.text)

for image in driver.find_elements(By.CLASS_NAME, 'market_row_img'):
    imagee.append(image.get_attribute('src'))

df = pd.DataFrame({'Name': namee,
                   'PRICE': pricee,
                   'IMAGE': imagee})

df.to_excel(f'./{file}.xlsx')

driver.close()

For conversion I use auto-py-to-exe. The conversion takes place without any errors, but as soon as the conversion has passed, I try to open the .exe, it opens and immediately closes. There is clearly some kind of error, but I do not have time to read it.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source