gpt4 book ai didi

python - 使用 curl 时让python发送回车键

转载 作者:行者123 更新时间:2023-12-04 05:08:01 25 4
gpt4 key购买 nike

我正在制作一个 python 脚本来 curl 奇幻曲棍球记分牌页面,调用 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()

最佳答案

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

为避免这种情况,将 URL 参数引用到 curl ,像这样:
curl -o /tmp/fantasyhockey.txt "http://...."

关于python - 使用 curl 时让python发送回车键,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15263930/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com