{"id":1172538,"date":"2025-01-15T16:50:42","date_gmt":"2025-01-15T08:50:42","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1172538.html"},"modified":"2025-01-15T16:50:45","modified_gmt":"2025-01-15T08:50:45","slug":"python%e5%a6%82%e4%bd%95%e5%90%af%e5%8a%a8%e6%89%8b%e6%9c%ba%e9%97%b9%e9%92%9f","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1172538.html","title":{"rendered":"Python\u5982\u4f55\u542f\u52a8\u624b\u673a\u95f9\u949f"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/26074610\/6cfde6f9-e5b4-4b3e-9a00-93591b456b32.webp\" alt=\"Python\u5982\u4f55\u542f\u52a8\u624b\u673a\u95f9\u949f\" \/><\/p>\n<p><p> <strong>Python\u53ef\u4ee5\u901a\u8fc7\u591a\u79cd\u65b9\u5f0f\u542f\u52a8\u624b\u673a\u95f9\u949f\uff0c\u6bd4\u5982\u4f7f\u7528\u7b2c\u4e09\u65b9\u5e93\u3001\u901a\u8fc7\u624b\u673a\u7684API\u63a5\u53e3\u3001\u6216\u8005\u901a\u8fc7\u81ea\u52a8\u5316\u5de5\u5177\u3002<\/strong>\u5176\u4e2d\uff0c\u4f7f\u7528\u7b2c\u4e09\u65b9\u5e93\u662f\u4e00\u79cd\u8f83\u4e3a\u7b80\u5355\u4e14\u6709\u6548\u7684\u65b9\u5f0f\u3002\u4e0b\u9762\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u5982\u4f55\u4f7f\u7528Python\u7b2c\u4e09\u65b9\u5e93\u201cpywhatkit\u201d\u6765\u542f\u52a8\u624b\u673a\u95f9\u949f\u3002<\/p>\n<\/p>\n<p><h3>\u4e00\u3001\u4f7f\u7528pywhatkit\u5e93<\/h3>\n<\/p>\n<p><h4>1\u3001\u5b89\u88c5pywhatkit\u5e93<\/h4>\n<\/p>\n<p><p>\u9996\u5148\uff0c\u786e\u4fdd\u4f60\u7684Python\u73af\u5883\u4e2d\u5df2\u7ecf\u5b89\u88c5\u4e86\u201cpywhatkit\u201d\u5e93\u3002\u5982\u679c\u6ca1\u6709\u5b89\u88c5\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u8fdb\u884c\u5b89\u88c5\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install pywhatkit<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2\u3001\u5bfc\u5165pywhatkit\u5e93<\/h4>\n<\/p>\n<p><p>\u5728\u4f60\u7684Python\u811a\u672c\u4e2d\uff0c\u5bfc\u5165\u201cpywhatkit\u201d\u5e93\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import pywhatkit<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>3\u3001\u4f7f\u7528sendwhatmsg\u65b9\u6cd5<\/h4>\n<\/p>\n<p><p><code>pywhatkit<\/code>\u5e93\u7684<code>sendwhatmsg<\/code>\u65b9\u6cd5\u53ef\u4ee5\u7528\u6765\u53d1\u9001WhatsApp\u6d88\u606f\uff0c\u8fd9\u91cc\u53ef\u4ee5\u5229\u7528\u8fd9\u4e2a\u65b9\u6cd5\u5728\u6307\u5b9a\u65f6\u95f4\u53d1\u9001\u6d88\u606f\u6765\u95f4\u63a5\u542f\u52a8\u95f9\u949f\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u7b80\u5355\u7684\u4f8b\u5b50\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import pywhatkit as kit<\/p>\n<h2><strong>\u53c2\u6570\uff1a\u63a5\u6536\u8005\u7684\u7535\u8bdd\u53f7\u7801\u3001\u6d88\u606f\u5185\u5bb9\u3001\u5c0f\u65f6\u3001\u5206\u949f<\/strong><\/h2>\n<p>kit.sendwhatmsg(&quot;+1234567890&quot;, &quot;It&#39;s time to wake up!&quot;, 7, 30)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u4e0a\u9762\u7684\u4f8b\u5b50\u4e2d\uff0c<code>sendwhatmsg<\/code>\u65b9\u6cd5\u5c06\u5728\u65e9\u4e0a7\u70b930\u5206\u53d1\u9001\u4e00\u6761\u6d88\u606f\u5230\u6307\u5b9a\u7684\u7535\u8bdd\u53f7\u7801\uff0c\u4ece\u800c\u8d77\u5230\u63d0\u9192\u7684\u4f5c\u7528\u3002<\/p>\n<\/p>\n<p><h3>\u4e8c\u3001\u4f7f\u7528Android\u7684Intent\u673a\u5236<\/h3>\n<\/p>\n<p><h4>1\u3001\u4f7f\u7528Android Intent\u542f\u52a8\u95f9\u949f<\/h4>\n<\/p>\n<p><p>Android\u7cfb\u7edf\u63d0\u4f9b\u4e86\u4e00\u79cd\u901a\u8fc7Intent\u673a\u5236\u542f\u52a8\u95f9\u949f\u7684\u65b9\u5f0f\u3002\u53ef\u4ee5\u901a\u8fc7Python\u7684<code>subprocess<\/code>\u6a21\u5757\u8c03\u7528Android\u7684ADB\u5de5\u5177\u6765\u5b9e\u73b0\u8fd9\u4e00\u70b9\u3002<\/p>\n<\/p>\n<p><h4>2\u3001\u5b89\u88c5ADB\u5de5\u5177<\/h4>\n<\/p>\n<p><p>\u9996\u5148\uff0c\u786e\u4fdd\u4f60\u7684\u7535\u8111\u4e0a\u5df2\u7ecf\u5b89\u88c5\u4e86ADB\u5de5\u5177\u3002\u5982\u679c\u6ca1\u6709\u5b89\u88c5\uff0c\u53ef\u4ee5\u53c2\u8003\u4ee5\u4e0b\u94fe\u63a5\u8fdb\u884c\u5b89\u88c5\uff1a<a href=\"https:\/\/developer.android.com\/studio\/releases\/platform-tools\">https:\/\/developer.android.com\/studio\/releases\/platform-tools<\/a><\/p>\n<\/p>\n<p><h4>3\u3001\u4f7f\u7528subprocess\u8c03\u7528ADB\u547d\u4ee4<\/h4>\n<\/p>\n<p><p>\u5728\u4f60\u7684Python\u811a\u672c\u4e2d\uff0c\u4f7f\u7528<code>subprocess<\/code>\u6a21\u5757\u8c03\u7528ADB\u547d\u4ee4\u6765\u542f\u52a8\u95f9\u949f\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u7b80\u5355\u7684\u4f8b\u5b50\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import subprocess<\/p>\n<h2><strong>\u8bbe\u7f6e\u95f9\u949f\u7684\u65f6\u95f4\uff08\u5c0f\u65f6\u548c\u5206\u949f\uff09<\/strong><\/h2>\n<p>hour = 7<\/p>\n<p>minute = 30<\/p>\n<h2><strong>\u6784\u9020ADB\u547d\u4ee4<\/strong><\/h2>\n<p>cmd = f&#39;adb shell am broadcast -a android.intent.action.SET_ALARM --ez skip_ui true --ei hour {hour} --ei minutes {minute}&#39;<\/p>\n<h2><strong>\u6267\u884cADB\u547d\u4ee4<\/strong><\/h2>\n<p>subprocess.run(cmd, shell=True)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u4e0a\u9762\u7684\u4f8b\u5b50\u4e2d\uff0c\u6211\u4eec\u901a\u8fc7ADB\u5de5\u5177\u53d1\u9001\u4e86\u4e00\u4e2a\u5e7f\u64adIntent\u6765\u8bbe\u7f6e\u95f9\u949f\u3002<code>skip_ui<\/code>\u53c2\u6570\u8bbe\u7f6e\u4e3a<code>true<\/code>\uff0c\u8868\u793a\u76f4\u63a5\u8bbe\u7f6e\u95f9\u949f\u800c\u4e0d\u663e\u793a\u8bbe\u7f6e\u754c\u9762\u3002<\/p>\n<\/p>\n<p><h3>\u4e09\u3001\u4f7f\u7528\u81ea\u52a8\u5316\u5de5\u5177<\/h3>\n<\/p>\n<p><h4>1\u3001\u4f7f\u7528Appium\u81ea\u52a8\u5316\u5de5\u5177<\/h4>\n<\/p>\n<p><p>Appium\u662f\u4e00\u4e2a\u5f00\u6e90\u7684\u81ea\u52a8\u5316\u5de5\u5177\uff0c\u53ef\u4ee5\u7528\u6765\u6d4b\u8bd5\u79fb\u52a8\u5e94\u7528\u3002\u53ef\u4ee5\u901a\u8fc7Appium\u6765\u542f\u52a8\u624b\u673a\u4e0a\u7684\u95f9\u949f\u5e94\u7528\u5e76\u8bbe\u7f6e\u95f9\u949f\u3002<\/p>\n<\/p>\n<p><h4>2\u3001\u5b89\u88c5Appium\u548c\u76f8\u5173\u5e93<\/h4>\n<\/p>\n<p><p>\u9996\u5148\uff0c\u786e\u4fdd\u4f60\u7684\u7535\u8111\u4e0a\u5df2\u7ecf\u5b89\u88c5\u4e86Appium\u548c\u76f8\u5173\u7684Python\u5e93\u3002\u5982\u679c\u6ca1\u6709\u5b89\u88c5\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u8fdb\u884c\u5b89\u88c5\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install Appium-Python-Client<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>3\u3001\u7f16\u5199\u81ea\u52a8\u5316\u811a\u672c<\/h4>\n<\/p>\n<p><p>\u5728\u4f60\u7684Python\u811a\u672c\u4e2d\uff0c\u4f7f\u7528Appium\u5e93\u7f16\u5199\u81ea\u52a8\u5316\u811a\u672c\u6765\u542f\u52a8\u95f9\u949f\u5e94\u7528\u5e76\u8bbe\u7f6e\u95f9\u949f\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u7b80\u5355\u7684\u4f8b\u5b50\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from appium import webdriver<\/p>\n<h2><strong>\u8bbe\u7f6eAppium\u670d\u52a1\u5668\u7684URL<\/strong><\/h2>\n<p>server_url = &#39;http:\/\/localhost:4723\/wd\/hub&#39;<\/p>\n<h2><strong>\u8bbe\u7f6e\u8bbe\u5907\u7684Desired Capabilities<\/strong><\/h2>\n<p>desired_caps = {<\/p>\n<p>    &#39;platformName&#39;: &#39;Android&#39;,<\/p>\n<p>    &#39;deviceName&#39;: &#39;emulator-5554&#39;,<\/p>\n<p>    &#39;appPackage&#39;: &#39;com.android.deskclock&#39;,<\/p>\n<p>    &#39;appActivity&#39;: &#39;.AlarmClock&#39;<\/p>\n<p>}<\/p>\n<h2><strong>\u521b\u5efaWebDriver\u5b9e\u4f8b<\/strong><\/h2>\n<p>driver = webdriver.Remote(server_url, desired_caps)<\/p>\n<h2><strong>\u8bbe\u7f6e\u95f9\u949f\u7684\u65f6\u95f4\uff08\u5c0f\u65f6\u548c\u5206\u949f\uff09<\/strong><\/h2>\n<p>hour = 7<\/p>\n<p>minute = 30<\/p>\n<h2><strong>\u67e5\u627e\u5e76\u70b9\u51fb\u6dfb\u52a0\u95f9\u949f\u6309\u94ae<\/strong><\/h2>\n<p>add_alarm_button = driver.find_element_by_accessibility_id(&#39;Add alarm&#39;)<\/p>\n<p>add_alarm_button.click()<\/p>\n<h2><strong>\u8bbe\u7f6e\u95f9\u949f\u65f6\u95f4<\/strong><\/h2>\n<p>time_picker = driver.find_element_by_class_name(&#39;android.widget.TimePicker&#39;)<\/p>\n<p>time_picker.set_time(hour, minute)<\/p>\n<h2><strong>\u4fdd\u5b58\u5e76\u542f\u52a8\u95f9\u949f<\/strong><\/h2>\n<p>save_button = driver.find_element_by_accessibility_id(&#39;Save&#39;)<\/p>\n<p>save_button.click()<\/p>\n<h2><strong>\u5173\u95edWebDriver<\/strong><\/h2>\n<p>driver.quit()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u4e0a\u9762\u7684\u4f8b\u5b50\u4e2d\uff0c\u6211\u4eec\u4f7f\u7528Appium\u542f\u52a8\u4e86\u95f9\u949f\u5e94\u7528\uff0c\u5e76\u901a\u8fc7\u81ea\u52a8\u5316\u811a\u672c\u8bbe\u7f6e\u4e86\u95f9\u949f\u65f6\u95f4\u3002<\/p>\n<\/p>\n<p><h3>\u56db\u3001\u603b\u7ed3<\/h3>\n<\/p>\n<p><p>\u901a\u8fc7\u4ee5\u4e0a\u51e0\u79cd\u65b9\u6cd5\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528Python\u542f\u52a8\u624b\u673a\u95f9\u949f\u3002<strong>\u4f7f\u7528\u7b2c\u4e09\u65b9\u5e93\u201cpywhatkit\u201d\u53ef\u4ee5\u65b9\u4fbf\u5730\u53d1\u9001\u63d0\u9192\u6d88\u606f<\/strong>\uff0c<strong>\u901a\u8fc7Android\u7684Intent\u673a\u5236\u53ef\u4ee5\u76f4\u63a5\u8bbe\u7f6e\u95f9\u949f<\/strong>\uff0c<strong>\u4f7f\u7528Appium\u81ea\u52a8\u5316\u5de5\u5177\u53ef\u4ee5\u6a21\u62df\u7528\u6237\u64cd\u4f5c\u8bbe\u7f6e\u95f9\u949f<\/strong>\u3002\u6bcf\u79cd\u65b9\u6cd5\u90fd\u6709\u5176\u4f18\u7f3a\u70b9\uff0c\u9009\u62e9\u9002\u5408\u81ea\u5df1\u7684\u65b9\u6cd5\u662f\u5173\u952e\u3002<\/p>\n<\/p>\n<p><p>\u5728\u5b9e\u9645\u5e94\u7528\u4e2d\uff0c\u53ef\u80fd\u9700\u8981\u6839\u636e\u5177\u4f53\u9700\u6c42\u9009\u62e9\u5408\u9002\u7684\u65b9\u6cd5\uff0c\u4f8b\u5982<strong>\u5982\u679c\u9700\u8981\u8de8\u5e73\u53f0\u652f\u6301\uff0c\u53ef\u4ee5\u8003\u8651\u4f7f\u7528\u7b2c\u4e09\u65b9\u5e93<\/strong>\uff0c<strong>\u5982\u679c\u9700\u8981\u66f4\u9ad8\u7684\u5b9a\u5236\u5316\uff0c\u53ef\u4ee5\u8003\u8651\u4f7f\u7528\u81ea\u52a8\u5316\u5de5\u5177<\/strong>\u3002\u5e0c\u671b\u4ee5\u4e0a\u5185\u5bb9\u5bf9\u4f60\u6709\u6240\u5e2e\u52a9\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>Python\u53ef\u4ee5\u5b9e\u73b0\u624b\u673a\u95f9\u949f\u529f\u80fd\u5417\uff1f<\/strong><br \/>\u662f\u7684\uff0cPython\u53ef\u4ee5\u901a\u8fc7\u4e00\u4e9b\u5e93\u548c\u5de5\u5177\u6765\u5b9e\u73b0\u624b\u673a\u95f9\u949f\u529f\u80fd\u3002\u6bd4\u5982\uff0c\u4f7f\u7528Python\u7684Kivy\u6216BeeWare\u7b49\u6846\u67b6\u53ef\u4ee5\u521b\u5efa\u79fb\u52a8\u5e94\u7528\u7a0b\u5e8f\uff0c\u5e76\u7ed3\u5408\u65f6\u95f4\u8c03\u5ea6\u5e93\u6765\u8bbe\u7f6e\u548c\u89e6\u53d1\u95f9\u949f\u3002\u901a\u8fc7\u8fd9\u4e9b\u5de5\u5177\uff0c\u7528\u6237\u80fd\u591f\u5728\u624b\u673a\u4e0a\u8fd0\u884cPython\u4ee3\u7801\uff0c\u4ece\u800c\u5b9e\u73b0\u81ea\u5b9a\u4e49\u7684\u95f9\u949f\u5e94\u7528\u3002<\/p>\n<p><strong>\u5728\u624b\u673a\u4e0a\u4f7f\u7528Python\u8bbe\u7f6e\u95f9\u949f\u9700\u8981\u54ea\u4e9b\u6b65\u9aa4\uff1f<\/strong><br \/>\u9996\u5148\uff0c\u9700\u8981\u9009\u62e9\u4e00\u4e2a\u652f\u6301Python\u7684\u79fb\u52a8\u5f00\u53d1\u6846\u67b6\uff0c\u5982Kivy\u6216BeeWare\u3002\u63a5\u4e0b\u6765\uff0c\u5b89\u88c5\u6240\u9700\u7684\u5e93\u548c\u73af\u5883\uff0c\u5e76\u7f16\u5199\u7a0b\u5e8f\u6765\u83b7\u53d6\u5f53\u524d\u65f6\u95f4\u3001\u8bbe\u7f6e\u95f9\u949f\u65f6\u95f4\u4ee5\u53ca\u521b\u5efa\u95f9\u949f\u89e6\u53d1\u7684\u97f3\u6548\u3002\u5728\u5b8c\u6210\u4ee3\u7801\u540e\uff0c\u5c06\u5176\u6253\u5305\u6210\u9002\u5408\u624b\u673a\u64cd\u4f5c\u7cfb\u7edf\u7684\u5e94\u7528\u683c\u5f0f\uff0c\u5e76\u5b89\u88c5\u5230\u624b\u673a\u4e0a\u3002<\/p>\n<p><strong>Python\u521b\u5efa\u7684\u95f9\u949f\u5e94\u7528\u53ef\u4ee5\u6dfb\u52a0\u54ea\u4e9b\u529f\u80fd\uff1f<\/strong><br \/>\u7528\u6237\u53ef\u4ee5\u5728Python\u521b\u5efa\u7684\u95f9\u949f\u5e94\u7528\u4e2d\u6dfb\u52a0\u591a\u79cd\u529f\u80fd\u3002\u4f8b\u5982\uff0c\u8bbe\u7f6e\u591a\u4e2a\u95f9\u949f\u3001\u9009\u62e9\u4e0d\u540c\u7684\u94c3\u58f0\u3001\u91cd\u590d\u95f9\u949f\u7684\u9891\u7387\u3001\u9707\u52a8\u6a21\u5f0f\u3001\u4ee5\u53ca\u7528\u6237\u754c\u9762\u7684\u4e2a\u6027\u5316\u8bbe\u8ba1\u3002\u8fd8\u53ef\u4ee5\u7ed3\u5408\u5929\u6c14\u4fe1\u606f\u6216\u65e5\u5386\u4e8b\u4ef6\uff0c\u8bbe\u7f6e\u667a\u80fd\u95f9\u949f\uff0c\u5e2e\u52a9\u7528\u6237\u66f4\u597d\u5730\u7ba1\u7406\u65f6\u95f4\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"Python\u53ef\u4ee5\u901a\u8fc7\u591a\u79cd\u65b9\u5f0f\u542f\u52a8\u624b\u673a\u95f9\u949f\uff0c\u6bd4\u5982\u4f7f\u7528\u7b2c\u4e09\u65b9\u5e93\u3001\u901a\u8fc7\u624b\u673a\u7684API\u63a5\u53e3\u3001\u6216\u8005\u901a\u8fc7\u81ea\u52a8\u5316\u5de5\u5177\u3002\u5176\u4e2d\uff0c\u4f7f [&hellip;]","protected":false},"author":3,"featured_media":1172541,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[37],"tags":[],"acf":[],"_links":{"self":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1172538"}],"collection":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/comments?post=1172538"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1172538\/revisions"}],"predecessor-version":[{"id":1172542,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1172538\/revisions\/1172542"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1172541"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1172538"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1172538"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1172538"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}