【问题标题】:Is there a way to use python to do specific things in an application?有没有办法使用 python 在应用程序中做特定的事情?
【发布时间】:2016-12-18 21:05:42
【问题描述】:

比如先打开Safari

os.system("open /Applications/Safari.app")

然后去一个用户输入别的东西,它就会被输入到搜索栏并被搜索到。

同样适用于本例

os.system("open /Applications/Messages.app")

然后向某人发送消息。

如果可能的话,这个例子:

os.system("open /Applications/Dictionary.app")

然后搜索一个词?

非常感谢:D

【问题讨论】:

    标签: python operating-system


    【解决方案1】:

    这不是它的工作原理。在您的示例中,您只是使用 python 来执行 shell 命令。程序打开后,它不会只为您提供有关正在发生的事情的信息,除非它专门设计用于这样做或支持某种 API。

    【讨论】:

      【解决方案2】:

      如果你想自动化网络任务 - 查看selenium

      Selenium Python 绑定提供了一个简单的 API 来使用 Selenium WebDriver 编写功能/验收测试。通过 Selenium Python API,您可以直观地访问 Selenium WebDriver 的所有功能。

      Selenium Python 绑定提供了方便的 API 来访问 Selenium WebDrivers,如 Firefox、Ie、Chrome、Remote 等。

      这是selenium and webdrivers的链接

      你可以这样做:

      from selenium import webdriver
      from selenium.webdriver.common.keys import Keys
      
      driver = webdriver.Firefox()
      driver.get("http://www.python.org")
      assert "Python" in driver.title
      elem = driver.find_element_by_name("q")
      elem.clear()
      elem.send_keys("pycon")
      elem.send_keys(Keys.RETURN)
      assert "No results found." not in driver.page_source
      driver.close()
      

      here for a breakdown of the code

      对于您的消息示例,您可以使用Skype4Py API

      【讨论】:

        【解决方案3】:

        这些都是 OS X 应用程序,所以我将迈出一大步,假设您使用的是 Mac。 Automator 应用程序可能更适合此任务,因为它基本上可以帮助您轻松编写 AppleScript 应用程序。

        【讨论】:

          【解决方案4】:

          对于网络自动化:

          1. Selenium Python Bindings
            我有一个详细的示例here 以及一些有用的链接。

          2. Splinter(比硒简单)

          【讨论】:

            【解决方案5】:

            为此,您需要使用 macbook 上名为 automator 的应用程序。这样,您将有权访问应用程序的源代码并对其进行编辑。

            【讨论】:

              猜你喜欢
              • 2015-08-13
              • 1970-01-01
              • 2021-04-29
              • 1970-01-01
              • 2014-10-01
              • 2015-03-25
              • 2012-03-03
              • 1970-01-01
              • 1970-01-01
              相关资源
              最近更新 更多