我遇到了一个问题,我最近搬到了一个vps.我正在尝试运行python cgi脚本,但我得到一个apache脚本标头的过早结束错误.
(我chmod + x脚本文件)
该脚本非常简单:
#!/usr/bin/env python
import cgi, cgitb
cgitb.enable()
print "Content-type: text/html"
print "<html><body>hello scritp</body></html>"
Run Code Online (Sandbox Code Playgroud)
现在如果我将脚本命名为test**.py**它在服务器上运行良好.但是,如果我以正确的方式执行,请将其称为测试**.cgi**我收到内部服务器错误.
我从终端运行脚本
./test.cgi
Run Code Online (Sandbox Code Playgroud)
我没有错
Content-type: text/html
<html><body>hello scritp</body></html>
Run Code Online (Sandbox Code Playgroud)
有没有人遇到过这个问题?并为它的解决方案?:)干杯
HIA
我在python中从stackexchange解析rss feed时遇到问题.当我尝试获取摘要节点时,将返回一个空列表
我一直试图解决这个问题,但无法理解.
任何人都可以帮忙吗?谢谢
In [3o]: import lxml.etree, urllib2
In [31]: url_cooking = 'http://cooking.stackexchange.com/feeds'
In [32]: cooking_content = urllib2.urlopen(url_cooking)
In [33]: cooking_parsed = lxml.etree.parse(cooking_content)
In [34]: cooking_texts = cooking_parsed.xpath('.//feed/entry/summary')
In [35]: cooking_texts
Out[35]: []
Run Code Online (Sandbox Code Playgroud)
In [3o]: import lxml.etree, urllib2
In [31]: url_cooking = 'http://cooking.stackexchange.com/feeds'
In [32]: cooking_content = urllib2.urlopen(url_cooking)
In [33]: cooking_parsed = lxml.etree.parse(cooking_content)
In [34]: cooking_texts = cooking_parsed.xpath('.//feed/entry/summary')
In [35]: cooking_texts
Out[35]: []
Run Code Online (Sandbox Code Playgroud)
我正在使用带xpath的lxml来解析epub3,xhtml内容文件.
我想选择li具有该属性的所有节点,epub:type="footnote"
例如
<li epub:type="footnote" id="fn14"> ... </li>
Run Code Online (Sandbox Code Playgroud)
我找不到合适的xpath表达式.
表达方式
//*[self::li][@id]
Run Code Online (Sandbox Code Playgroud)
选择li具有属性id的所有节点,但是当我尝试时
//*[self::li][@epub:type]
Run Code Online (Sandbox Code Playgroud)
我收到了错误
lxml.etree.XPathEvalError: Undefined namespace prefix
Run Code Online (Sandbox Code Playgroud)
XML是
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops">
<head>
<meta charset="utf-8" />
<link rel="stylesheet" href="stylesheet.css" />
</head>
<body>
<section class="footnotes">
<hr />
<ol>
<li id="fn1" epub:type="footnote">
<p>See foo</p>
</li>
</ol>
</section>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
关于如何编写正确表达式的任何建议?
我试图在python中编写一个正则表达式来查找Markdown文本字符串中的URL.一旦找到一个网址,我想检查这是否被一个降价链接包裹:文字我对后者有问题.我正在使用正则表达式 - link_exp - 进行搜索,但结果并不是我所期望的,并且无法理解它.
这可能是我看不到的简单事情.
这里是link_exp正则表达式的代码和解释
import re
text = '''
[Vocoder](http://en.wikipedia.org/wiki/Vocoder )
[Turing]( http://en.wikipedia.org/wiki/Alan_Turing)
[Autotune](http://en.wikipedia.org/wiki/Autotune)
http://en.wikipedia.org/wiki/The_Voder
'''
urls = re.findall('http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+', text) #find all urls
for url in urls:
url = re.escape(url)
link_exp = re.compile('\[.*\]\(\s*{0}\s*\)'.format(url) ) # expression with url wrapped in link syntax.
search = re.search(link_exp, text)
if search != None:
print url
# expression should translate to:
# \[ - literal [
# .* - any character or no character
# \] - literal ]
# \( …Run Code Online (Sandbox Code Playgroud)