【问题标题】:Paste to codepad.org using bash or curl使用 bash 或 curl 粘贴到 codepad.org
【发布时间】:2011-01-15 10:14:30
【问题描述】:

如何使用 curl 从命令行粘贴到 codepad.org?

【问题讨论】:

    标签: bash curl pastebin


    【解决方案1】:

    是的,你可以用 curl 做到这一点。假设您的代码是 Python 并且在 myfile.python 中,您可以这样做:

    $ curl -d "lang=Python&submit=Submit" --data-urlencode code@myfile.py codepad.org
    

    (经过编辑使其工作。)

    【讨论】:

    • 这只会在新粘贴上发布“@myfile.c”。我需要一种上传整个文件的方法
    • 我实际上是在粘贴 python 代码,但在我执行命令的同一目录中确实有以 @ 命名的文件。 $ curl -d lang=Python -d code=@myfile.py -d private=False -d submit=提交 codepad.org 仍然只发布文件名
    • 对不起,你是对的,它不起作用。我已经编辑了我的回复,现在它对我有用。请让我知道它是否也适合您。
    • curl 方法仍然不适合我。它说 --data-urlencode 选项未知
    • 该选项是在 curl 7.18.0(2008 年 1 月)中引入的,所以它是最近的。
    【解决方案2】:

    这是一个 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
    

    【讨论】:

      【解决方案3】:

      你也可以使用reval:

      reval test.py
      reval -l ruby -e 'p 2+2'
      reval prog.hs -p # make private
      

      【讨论】:

        猜你喜欢
        • 2017-11-16
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-08-15
        • 2011-01-19
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多