{"id":11750,"date":"2023-12-11T15:44:09","date_gmt":"2023-12-11T07:44:09","guid":{"rendered":"https:\/\/www.yimenyun.cn\/emen\/?p=11750"},"modified":"2023-12-11T15:44:09","modified_gmt":"2023-12-11T07:44:09","slug":"selenium%e6%89%93%e5%8c%85%e6%88%90exe%e6%96%87%e4%bb%b6%e5%a6%82%e4%bd%95%e5%81%9a","status":"publish","type":"post","link":"https:\/\/www.yimenyun.cn\/emen\/11750\/","title":{"rendered":"selenium\u6253\u5305\u6210exe\u6587\u4ef6\u5982\u4f55\u505a?"},"content":{"rendered":"

Selenium\u662f\u4e00\u4e2a\u5e7f\u6cdb\u4f7f\u7528\u7684\u81ea\u52a8\u5316\u6d4b\u8bd5\u5de5\u5177\uff0c\u5b83\u53ef\u4ee5\u6a21\u62df\u7528\u6237\u5728\u6d4f\u89c8\u5668\u4e2d\u7684\u64cd\u4f5c\uff0c\u4f8b\u5982\u70b9\u51fb\u3001\u8f93\u5165\u6587\u672c\u3001\u63d0\u4ea4\u8868\u5355\u7b49\u7b49\u3002\u4f46\u662f\uff0c\u4f7f\u7528Selenium\u9700\u8981\u5b89\u88c5Python\u73af\u5883\u548c\u76f8\u5173\u7684\u5e93\uff0c\u8fd9\u5bf9\u4e8e\u4e00\u4e9b\u4e0d\u719f\u6089Python\u7684\u7528\u6237\u6765\u8bf4\u53ef\u80fd\u6bd4\u8f83\u56f0\u96be\u3002\u56e0\u6b64\uff0c\u5c06Selenium\u6253\u5305\u6210exe\u6587\u4ef6\u53ef\u4ee5\u65b9\u4fbf\u5730\u5728\u6ca1\u6709Python\u73af\u5883\u7684\u673a\u5668\u4e0a\u8fd0\u884c\u3002<\/p>\n

\u6253\u5305Selenium\u6210exe\u6587\u4ef6\u7684\u539f\u7406\u662f\u5c06Python\u4ee3\u7801\u548c\u76f8\u5173\u7684\u4f9d\u8d56\u5e93\u6253\u5305\u6210\u4e00\u4e2a\u53ef\u6267\u884c\u6587\u4ef6\uff0c\u7528\u6237\u53ea\u9700\u8981\u53cc\u51fb\u8be5\u6587\u4ef6\u5373\u53ef\u8fd0\u884c\u3002\u4e0b\u9762\uff0c\u6211\u4eec\u5c06\u4ecb\u7ecd\u4e24\u79cd\u5e38\u7528\u7684\u6253\u5305\u65b9\u5f0f\u3002<\/p>\n

1. pyinstaller\u6253\u5305<\/p>\n

pyinstaller\u662f\u4e00\u4e2a\u5e38\u7528\u7684Python\u6253\u5305\u5de5\u5177\uff0c\u5b83\u53ef\u4ee5\u5c06Python\u4ee3\u7801\u548c\u4f9d\u8d56\u5e93\u6253\u5305\u6210\u4e00\u4e2a\u53ef\u6267\u884c\u6587\u4ef6\u3002\u4e0b\u9762\u662f\u4f7f\u7528pyinstaller\u6253\u5305Selenium\u7684\u6b65\u9aa4\uff1a<\/p>\n

\u7b2c\u4e00\u6b65\uff1a\u5b89\u88c5pyinstaller<\/p>\n

\u4f7f\u7528pip\u5b89\u88c5pyinstaller\uff1a<\/p>\n

“`<\/p>\n

pip install pyinstaller<\/p>\n

“`<\/p>\n

\u7b2c\u4e8c\u6b65\uff1a\u521b\u5efa\u6253\u5305\u6587\u4ef6<\/p>\n

\u5728Selenium\u4ee3\u7801\u6240\u5728\u7684\u76ee\u5f55\u4e0b\uff0c\u6267\u884c\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n

“`<\/p>\n

pyinstaller –onefilewindows\u6253\u5305\u5de5\u5177<\/a> your_script_name.py<\/p>\n

“`<\/p>\n

\u5176\u4e2d\uff0c–onefile\u9009\u9879\u8868\u793a\u5c06\u6240\u6709\u6587\u4ef6\u6253\u5305\u6210\u4e00\u4e2a\u53ef\u6267\u884c\u6587\u4ef6\uff0cyour_script_name.py\u662fSelenium\u4ee3\u7801\u7684\u6587\u4ef6\u540d\u3002<\/p>\n

\u7b2c\u4e09\u6b65\uff1a\u8fd0\u884c\u6253\u5305\u6587\u4ef6<\/p>\n

\u5728dist\u76ee\u5f55\u4e0b\uff0c\u53ef\u4ee5\u627e\u5230\u6253\u5305\u597d\u7684\u53ef\u6267\u884c\u6587\u4ef6\uff0c\u53cc\u51fb\u5373\u53ef\u8fd0\u884c\u3002<\/p>\n

2. cx_Freeze\u6253\u5305<\/p>\n

cx_Freeze\u662f\u53e6\u4e00mac\u5e94\u7528\u5f00\u53d1<\/a>\u4e2aPython\u6253\u5305\u5de5\u5177\uff0c\u5b83\u4e5f\u53ef\u4ee5\u5c06Python\u4ee3\u7801\u548c\u4f9d\u8d56\u5e93\u6253\u5305\u6210\u4e00\u4e2a\u53ef\u6267\u884c\u6587\u4ef6\u3002\u4e0b\u9762\u662f\u4f7f\u7528cx_Freeze\u6253\u5305Selenium\u7684\u6b65\u9aa4\uff1a<\/p>\n

\u7b2c\u4e00\u6b65\uff1a\u5b89\u88c5cx_Freeze<\/p>\n

\u4f7f\u7528pip\u5b89\u88c5cx_Freeze\uff1a<\/p>\n

“`<\/p>\n

pip install cx_Freeze<\/p>\n

“`<\/p>\n

\u7b2c\u4e8c\u6b65\uff1a\u521b\u5efasetup.py\u6587\u4ef6<\/p>\n

\u5728Selenium\u4ee3\u7801\u6240\u5728\u7684\u76ee\u5f55\u4e0b\uff0c\u521b\u5efa\u4e00\u4e2a\u540d\u4e3asetup.py\u7684\u6587\u4ef6\uff0c\u8f93\u5165\u4ee5\u4e0b\u5185\u5bb9\uff1a<\/p>\n

“`python<\/p>\n

from cx_Freez<\/p>\n

<\/figure>\n<\/p>\n

e import setup, Executable<\/p>\n

setup(<\/p>\n

name=’your_script_name’,<\/p>\n

version=’1.0′,<\/p>\n

description=’Selenium script’,<\/p>\n

executables=[Executable(‘your_script_name.py’)]<\/p>\n

)<\/p>\n

“`<\/p>\n

\u5176\u4e2d\uff0cname\u8868\u793a\u6253\u5305\u540e\u7684\u6587\u4ef6\u540d\uff0cversion\u8868\u793a\u7248\u672c\u53f7\uff0cdescription\u8868\u793a\u6587\u4ef6\u63cf\u8ff0\uff0cExecutable\u8868\u793a\u8981\u6253\u5305\u7684\u6587\u4ef6\u540d\u3002<\/p>\n

\u7b2c\u4e09\u6b65\uff1a\u521b\u5efa\u6253\u5305\u6587\u4ef6<\/p>\n

\u5728Selenium\u4ee3\u7801\u6240\u5728\u7684\u76ee\u5f55\u4e0b\uff0c\u6267\u884c\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n

“`<\/p>\n

python setup.py build<\/p>\n

“`<\/p>\n

\u8fd9\u5c06\u5728build\u76ee\u5f55\u4e0b\u751f\u6210\u53ef\u6267\u884c\u6587\u4ef6\u3002<\/p>\n

\u7b2c\u56db\u6b65\uff1a\u8fd0\u884c\u6253\u5305\u6587\u4ef6<\/p>\n

\u5728build\u76ee\u5f55\u4e0b\uff0c\u53ef\u4ee5\u627e\u5230\u6253\u5305\u597d\u7684\u53ef\u6267\u884c\u6587\u4ef6\uff0c\u53cc\u51fb\u5373\u53ef\u8fd0\u884c\u3002<\/p>\n

\u603b\u7ed3<\/p>\n

\u4ee5\u4e0a\u662f\u4e24\u79cd\u5e38\u7528\u7684\u6253\u5305Selenium\u6210exe\u6587\u4ef6\u7684\u65b9\u6cd5\uff0c\u5b83\u4eec\u7684\u539f\u7406\u90fd\u662f\u5c06Python\u4ee3\u7801\u548c\u4f9d\u8d56\u5e93\u6253\u5305\u6210\u4e00\u4e2a\u53ef\u6267\u884c\u6587\u4ef6\u3002\u4f7f\u7528\u6253\u5305\u540e\u7684\u6587\u4ef6\u53ef\u4ee5\u65b9\u4fbf\u5730\u5728\u6ca1\u6709Python\u73af\u5883\u7684\u673a\u5668\u4e0a\u8fd0\u884c\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"

Selenium\u662f\u4e00\u4e2a\u5e7f\u6cdb\u4f7f\u7528\u7684\u81ea\u52a8\u5316\u6d4b\u8bd5\u5de5\u5177\uff0c\u5b83\u53ef\u4ee5\u6a21\u62df\u7528\u6237\u5728\u6d4f\u89c8\u5668\u4e2d\u7684\u64cd\u4f5c\uff0c\u4f8b\u5982\u70b9\u51fb\u3001\u8f93\u5165\u6587\u672c\u3001\u63d0\u4ea4\u8868\u5355\u7b49\u7b49\u3002\u4f46\u662f\uff0c\u4f7f\u7528Selenium\u9700\u8981\u5b89\u88c5Python\u73af\u5883\u548c\u76f8\u5173\u7684\u5e93\uff0c\u8fd9\u5bf9\u4e8e\u4e00\u4e9b\u4e0d\u719f\u6089Pyt<\/p>\n","protected":false},"author":7,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[17070,29,256,17069,16],"topic":[],"class_list":["post-11750","post","type-post","status-publish","format-standard","hentry","category-exekf","tag-windowsios","tag-29","tag-256","tag-exe","tag-16"],"_links":{"self":[{"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/posts\/11750","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/users\/7"}],"replies":[{"embeddable":true,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/comments?post=11750"}],"version-history":[{"count":1,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/posts\/11750\/revisions"}],"predecessor-version":[{"id":11809,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/posts\/11750\/revisions\/11809"}],"wp:attachment":[{"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/media?parent=11750"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/categories?post=11750"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/tags?post=11750"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/topic?post=11750"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}