【问题标题】:Looking for multiple things in a string在一个字符串中寻找多个东西
【发布时间】:2012-06-10 22:51:34
【问题描述】:

我正在尝试制作一个在输入 OPEN 命令时打开 url 的脚本。这是针对我正在创建的 IRC 机器人。我正在努力做到这一点

打开http://url.com 并打开网址。这是我目前所拥有的。

import webbrowser
test = s.recv(1024)

if test.find("http://") != 1:
        webbrowser.open(test)

else:
    print "it didnt work"

老实说,我不知道这是怎么做到的。

【问题讨论】:

  • 呃,你现在有什么?
  • 第二个大胡子。代码 值得发布(我希望 :)
  • 发布代码,它可能会帮助我们更好地了解您所获得的内容。只需插入 cmets 说明在您还没有真正的代码的地方应该发生什么。
  • 我做了,我真的不明白这是怎么做到的。
  • 我正在尝试从我的 irc 客户端创建它,因此我可以编写 OPEN google.com,它会在运行 python 脚本的计算机上打开该 URL。

标签: python irc bots


【解决方案1】:

我想通了

import webbrowser
#command is OPEN http://url.com
a = raw_input("Command: ")

if "OPEN" in a:
    url = a.strip("OPEN ")
    webbrowser.open(url)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-03-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-07-27
    相关资源
    最近更新 更多