【问题标题】:Make python send the enter key when using curl使python在使用curl时发送回车键
【发布时间】:2013-03-07 13:54:19
【问题描述】:

我正在制作一个 python 脚本来卷曲幻想曲棍球记分牌页面,调用 perl 以正则表达式替换球队名称和分数,并显示它。正则表达式已全部设置,但现在我无法获取网页。我注意到当我在运行

后在我的计算机上执行此操作时
curl -o /tmp/fantasyhockey.txt http://games.espn.go.com/fhl/scor...

command,按回车键一次会启动它,然后再次按它会退出并创建我的页面。如何强制 python 按回车键?出于好奇,它为什么要等待?

编辑:这是脚本。没什么大不了的。

import os
def main():

    os.system("curl -o /tmp/fantasyhockey.txt http://games.espn.go.com/fhl/scoreboar\
    d?leagueId=xxxxx&seasonId=2013")
    unfix = open("/tmp/fantasyhockey.txt", "r").read().replace('\n', '')
    outfile = open("/tmp/fantasyhockey2.txt", "w")
    outfile.write(unfix)
    outfile.close()
    os.system("perl regex.pl < /tmp/fantasyhockey2.txt")
    os.system("rm /tmp/fantasyhockey*")
main()

【问题讨论】:

  • 你能介绍一下执行 curl 的脚本吗?
  • 包括在内。也可能有更好的方法来使用 curl 而不是强迫 python 做一些奇怪的事情。

标签: python bash curl


【解决方案1】:

URL 中的&amp; 字符在shell 中具有特殊含义(它将程序发送到后台)。这就是您必须按 Enter 键的原因。

为避免这种情况,请将 URL 参数引用到 curl,如下所示:

curl -o /tmp/fantasyhockey.txt "http://...."

【讨论】:

    猜你喜欢
    • 2020-11-20
    • 1970-01-01
    • 2021-02-17
    • 1970-01-01
    • 1970-01-01
    • 2014-04-29
    • 1970-01-01
    • 2018-09-18
    • 1970-01-01
    相关资源
    最近更新 更多