可执行的Tkinter加上硒

时间:2016-10-01 19:58:35

标签: python selenium executable pyinstaller cx-freeze

好吧,我很难做到这一点,我尝试过Cx_freeze

但它显示了这个:

With Cx_freeze

这是设置:

import sys
from cx_Freeze import setup, Executable

# Dependencies are automatically detected, but it might need fine tuning.
build_exe_options = {"packages": ["os"], "excludes": ["tkinter","schedule","selenium"]}

# GUI applications require a different base on Windows (the default is for a
# console application).
base = None
if sys.platform == "win32":
    base = "Win32GUI"

setup(  name = "Yad2AutoAd",
        version = "0.1",
        description = "Auto Jumper for Yad2 Advertises",
        options = {"build_exe": build_exe_options},
        executables = [Executable("Yad2Ads.py", base=base)])

并使用pyinstaller显示:

  Traceback (most recent call last):
  File "site-packages\selenium\webdriver\common\service.py", line 64, in start
  File "subprocess.py", line 859, in __init__
  File "subprocess.py", line 1114, in _execute_child
FileNotFoundError: [WinError 2] \u200f\u200fלמערכת אין אפשרות לאתר את הקובץ שצוי
ן

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "Yad2Adv.py", line 9, in <module>
  File "site-packages\selenium\webdriver\chrome\webdriver.py", line 62, in __ini
t__
  File "site-packages\selenium\webdriver\common\service.py", line 71, in start
selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executabl
e needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chrome
driver/home

Failed to execute script Yad2Adv
Exception ignored in: <bound method Service.__del__ of <selenium.webdriver.chrom
e.service.Service object at 0x0000000002C3D668>>
Traceback (most recent call last):
  File "site-packages\selenium\webdriver\common\service.py", line 163, in __del_
_
  File "site-packages\selenium\webdriver\common\service.py", line 135, in stop
AttributeError: 'Service' object has no attribute 'process'

那么它的类型是一个相同的错误我认为,我该怎么办我试图将selenium文件夹插入到exe文件的同一文件夹中。 我认为这篇文章非常详细,如果看起来像一个长脚本,对不起。 只是想确保你们明白这个问题。 提前致谢! P.S 初始化代码webdriver:

driver = webdriver.PhantomJS()

并且PhantomJs.exe与项目位于同一文件夹中。

1 个答案:

答案 0 :(得分:0)

Saurabh Gaur告诉我,如果我正在初始化网络驱动程序,再次重新思考它并搜索它,那么你必须制作可执行路径 为你的webdriver例如:

phantomdriver = r"C:\Users\Bar\PycharmProjects\Yad2FinalFix\phantomjs.exe"
driver = webdriver.PhantomJS(executable_path=phantomdriver)

这解决了我的问题,谢谢Saurabh Gaur你多次救了我!