如何使用 curl 从命令行粘贴到 codepad.org?
问问题
2290 次
3 回答
7
这是一个 Python 脚本
import urllib
import urllib2
url = 'http://codepad.org'
content=open("myscript.py").read()
values = {'lang' : 'Python',
'code' : content,
'submit':'Submit'}
data = urllib.urlencode(values)
req = urllib2.Request(url, data)
response = urllib2.urlopen(req)
the_page = response.read()
for href in the_page.split("</a>"):
if "Link:" in href:
ind=href.index('Link:')
found = href[ind+5:]
for i in found.split('">'):
if '<a href=' in i:
print "The link: " ,i.replace('<a href="',"").strip()
输出
$ python python.py
The link: http://codepad.org/W0G8HIzM
于 2010-02-10T20:42:04.990 回答
2
是的,你可以用 curl 做到这一点。假设您的代码是 Python 并且在 myfile.python 中,您可以这样做:
$ curl -d "lang=Python&submit=Submit" --data-urlencode code@myfile.py codepad.org
(编辑使其工作。)
于 2010-02-10T19:51:07.390 回答
0
您还可以使用reval:
reval test.py
reval -l ruby -e 'p 2+2'
reval prog.hs -p # make private
于 2012-02-03T05:25:06.973 回答