0

我正在尝试 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()
4

1 回答 1

1
  1. for 循环的最后一行有语法错误:

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

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

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

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

于 2012-12-03T09:45:28.797 回答