2

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

curl -o /tmp/fantasyhockey.txt http://games.espn.go.com/fhl/scor...

命令,按一次回车将启动它,然后再按一次将退出并制作我的页面。如何强制 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()
4

1 回答 1

3

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

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

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

于 2013-03-07T05:54:19.113 回答