Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/70.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何将python脚本转换为web界面_Python_Html - Fatal编程技术网

如何将python脚本转换为web界面

如何将python脚本转换为web界面,python,html,Python,Html,我正在尝试转换此python脚本(diff.py) 在我的网站上,也就是一个网页界面。他提供了你可以下载的脚本,我通过命令行让它在我的windows电脑上运行,但我希望它也能在我的服务器上运行。我是如此接近。这是我到目前为止所拥有的 这是我的html文档- <form action="/cgi-bin/diff.py" method="get"><p> <strong>Old URL:</strong> <input name="old" t

我正在尝试转换此python脚本(diff.py)

在我的网站上,也就是一个网页界面。他提供了你可以下载的脚本,我通过命令行让它在我的windows电脑上运行,但我希望它也能在我的服务器上运行。我是如此接近。这是我到目前为止所拥有的

这是我的html文档-

<form action="/cgi-bin/diff.py" method="get"><p>
<strong>Old URL:</strong> <input name="old" type="text"><br>
<strong>New URL:</strong> <input name="new" type="text"><br>
<input value="Diff!" type="submit">
</p></form>
有人知道怎么了吗

好的,下面是我使用print open(a).read()时出现的错误---

Python脚本中出现问题。下面是导致错误的函数调用序列,按发生顺序排列。
E:\xampp\cgi-bin\diff2.py in()
19 b=形式[‘新’]。值
20
21打印打开(a).read()
22
23
内置开放=,a=http://www.google.com“,)。读取未定义
:[Errno 2]没有这样的文件或目录:'http://www.google.com'
args=(2,‘没有这样的文件或目录’)
errno=2
filename='1http://www.google.com'
消息=“”
strerror='没有这样的文件或目录'
好吧,我想这是我自己想出来的。以下是必要的修改。我在原始代码的开头停了下来-

#!G:\Program Files\Python25\python.exe
"""HTML Diff: http://www.aaronsw.com/2002/diff
Rough code, badly documented. Send me comments and patches.

__author__ = 'Aaron Swartz <me@aaronsw.com>'
__copyright__ = '(C) 2003 Aaron Swartz. GNU GPL 2 or 3.'
__version__ = '0.22' """


import cgi
import cgitb; cgitb.enable()
form = cgi.FieldStorage()
reshtml = """Content-Type: text/html\n
<html>
<head><title>Tonys Test</title></head>
<body>
"""
print reshtml
old2 = form['old'].value
new2 = form['new'].value

import urllib2

a = urllib2.urlopen(old2).read()
b = urllib2.urlopen(new2).read()

#print a
#print b

import difflib, string
#!G:\Program Files\Python25\python.exe
“”“HTML差异:http://www.aaronsw.com/2002/diff
粗糙的代码,糟糕的文档。给我发评论和补丁。
__作者:艾伦·斯瓦茨
__版权所有‘(C)2003 Aaron Swartz.GNU GPL 2或3。’
__版本='0.22''
导入cgi
进口cgib;cgib.enable()
form=cgi.FieldStorage()
reshtml=“”内容类型:text/html\n
托尼试验
"""
打印reshtml
old2=形式['old'].值
new2=形式['new'].值
导入urllib2
a=urllib2.urlopen(old2.read)()
b=urllib2.urlopen(new2.read)()
#打印
#打印b
导入difflib,字符串
我说得太快了。它有效,但没有突出差异。我只为旧版本打了删除线。我试着在我剪下的部分加上,应该会突出显示,但不起作用。我得到了我的原始错误声明。我会继续努力的

好了,终于开始工作了。我必须在末尾添加此代码-

def htmlDiff(a, b):
    f1, f2 = a.find('</head>'), a.find('</body>')
    ca = a[f1+len('</head>'):f2]

    f1, f2 = b.find('</head>'), b.find('</body>')
    cb = b[f1+len('</head>'):f2]

    r = textDiff(ca, cb)
    hdr = '<style type="text/css"><!-- ins{background-color: #bbffbb} del{background-color: #ffcccc}--></style></head>'
    return b[:f1] + hdr + r + b[f2:]


print htmlDiff(a, b)
print '</body>'
print '</html>'
def htmlDiff(a,b):
f1,f2=a.find(“”),a.find(“”)
ca=a[f1+len(''):f2]
f1,f2=b.find(“”),b.find(“”)
cb=b[f1+len(''):f2]
r=textDiff(ca,cb)
hdr=''
返回b[:f1]+hdr+r+b[f2:]
打印htmlDiff(a、b)
打印“
打印“

我在0.1版本下载中找到了这段代码

这个区块就是问题所在:

if __name__ == '__main__':
    import sys
    try:
        a, b = sys.argv[1:3]
    except ValueError:
        print "htmldiff: highlight the differences between two html files"
        print "usage: " + sys.argv[0] + " a b"
        sys.exit(1)
移除它

这一行:

print textDiff(open(a).read(), open(b).read())
应该成为

print textDiff(a, b)

你的缩进被你的浆糊弄乱了。可能想检查一下。@tyree:打印出
a
b
的值,看看你得到了什么。请修正你在问题中的缩进埃里克,我在阅读说明后插入这个有困难,我会再看一遍。我在大多数行中使用了4个空格。我打印了a和b,并得到了我在表单字段中输入的2个URL,所以这似乎有效。当然,我得到了一个错误。看起来它不是在寻找一个URL,而是一个目录或文件——我在这里发布代码时遇到了很大的问题,并且有5分钟的时间限制。
def htmlDiff(a, b):
    f1, f2 = a.find('</head>'), a.find('</body>')
    ca = a[f1+len('</head>'):f2]

    f1, f2 = b.find('</head>'), b.find('</body>')
    cb = b[f1+len('</head>'):f2]

    r = textDiff(ca, cb)
    hdr = '<style type="text/css"><!-- ins{background-color: #bbffbb} del{background-color: #ffcccc}--></style></head>'
    return b[:f1] + hdr + r + b[f2:]


print htmlDiff(a, b)
print '</body>'
print '</html>'
if __name__ == '__main__':
    import sys
    try:
        a, b = sys.argv[1:3]
    except ValueError:
        print "htmldiff: highlight the differences between two html files"
        print "usage: " + sys.argv[0] + " a b"
        sys.exit(1)
print textDiff(open(a).read(), open(b).read())
print textDiff(a, b)