【发布时间】:2011-01-15 10:14:30
【问题描述】:
如何使用 curl 从命令行粘贴到 codepad.org?
【问题讨论】:
如何使用 curl 从命令行粘贴到 codepad.org?
【问题讨论】:
是的,你可以用 curl 做到这一点。假设您的代码是 Python 并且在 myfile.python 中,您可以这样做:
$ curl -d "lang=Python&submit=Submit" --data-urlencode code@myfile.py codepad.org
(经过编辑使其工作。)
【讨论】:
这是一个 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
【讨论】:
你也可以使用reval:
reval test.py
reval -l ruby -e 'p 2+2'
reval prog.hs -p # make private
【讨论】: