Cron jobbin'一个python脚本:中途停止

2024-06-26 01:44:11 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试cronjob我的python脚本。我通过cPanel设置它,我的python脚本生成一个html文件,就像它应该生成的那样,所以我知道命令是正确的(只是“python/path”对吗?)在

但是,我生成的html在执行到一半时停止(就在第二个f.write()之后,这时for循环应该开始了)。在

当我在本地执行这个脚本时,我没有遇到任何问题,会产生什么结果?在

from SearchPhone import SearchPhone

phones = ["Iphone 3", "Iphone 4", "Iphone 5","Galaxy s3", "Galaxy s2", "LG Lucid", "LG Esteem", "HTC One S", "Droid 4",
          "Droid RAZR MAXX", "HTC EVO", "Galaxy Nexus", "LG Optimus 2", "LG Ignite",
          "Galaxy Note", "HTC Amaze", "HTC Rezound", "HTC Vivid", "HTC Rhyme", "Motorola Photon",
          "Motorola Milestone", "myTouch slide", "HTC Status", "Droid 3", "HTC Evo 3d", "HTC Wildfire",
          "LG Optimus 3d", "HTC ThunderBolt", "Incredible 2", "Kyocera Echo", "Galaxy S 4g",
          "HTC Inspire", "LG Optimus 2x", "Samsung Gem", "HTC Evo Shift", "Nexus S", "LG Axis", "Droid 2",
          "G2", "Droid x", "Droid Incredible" 
          ]

f = open('celly.html','w')


f.write("""<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Celly Blue Book</title>
</head>

<body>
</body>
</html>
""")

#table
f.write('<table width="100%" border="1">')
for x in phones:
    y = SearchPhone(x)
    f.write( "\t<tr>")
    f.write( "\t\t<td>" + str(y[0]) + "</td>")
    f.write( "\t\t<td>" + str(y[1]) + "</td>")
    f.write( "\t\t<td>" + str(y[2]) + "</td>")
    f.write( "\t\t<td>" + str(y[3]) + "</td>")
    f.write( "\t\t<td>" + str(y[4]) + "</td>")
    f.write( "\t</tr>"

f.write('</table>')

f.close()

Tags: 脚本httpforhtmltablegalaxywritetd
1条回答
网友
1楼 · 发布于 2024-06-26 01:44:11
  1. for循环中的最后一行有语法错误:

    f.write( "\t</tr>"

  2. 您可能没有对生产服务器的写入权限。 试试这个。

f = open('/tmp/celly.html','w')

如果这是有效的,那么就是写权限问题。 检查您的权限 celly.html当前文件夹中的文件。它应该是可写的。在

相关问题 更多 >