English 中文(简体)
采用Ruby或Adhurc等语言与APICS[封闭]互动
原标题:Using a language such as Ruby or Python to interact with API s [closed]

我期待开始建立网站。 我需要基本的儿童基金会功能。

我理解在废墟和花 the中如何做到这一点的基本原理,但这里我 st着:

我如何在Ruby/Python提出GET或POST的要求?

我试图与其他人接触APIC,我知道我需要的是怎样才能在编码时提及和使用这种扼杀。

Example: I want to reference a users profile, and count the number of posts they ve made.

I know the URL looks something like this: http://www.coolwebsite.com/users?bobsgreat?postcount

这给他的职位带来了价值。

我怎么能把这个数字带入我的Sharmascript-,然后我怎么能把这个数字写成一个供观看的超文本档案?

如果我在这里要求很多话,那么问题随着我开始撰写文件而增加。

最佳回答

这是你如何在python中做到这一点的一个非常粗略的例子。 需要对你的具体情况进行修改,但希望能够开始:

import urllib
import urllib2
url = "http://www.coolwebsite.com"
post = urllib.urlencode({"users":"bob", "bobsgreat":"yes", "postcount":"14"})

request = urllib2.Request(url, post)
socket = urllib2.urlopen(request)

hdrs = socket.headers
source = socket.read()
socket.close()

print "---- Headers -----"
print hdrs
print "---- Source HTML -----"
print source
print "---- END -----"

value = 0
for line in source.splitlines():
    if not line.strip():  continue
    if line.startswith("value="):
        try:
            value = line.split("=")
        except IndexError:
            pass
    if value > 0:
        break

open("some.html", "w").write("value is: %d" % value)
问题回答




相关问题
Can Django models use MySQL functions?

Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...

An enterprise scheduler for python (like quartz)

I am looking for an enterprise tasks scheduler for python, like quartz is for Java. Requirements: Persistent: if the process restarts or the machine restarts, then all the jobs must stay there and ...

How to remove unique, then duplicate dictionaries in a list?

Given the following list that contains some duplicate and some unique dictionaries, what is the best method to remove unique dictionaries first, then reduce the duplicate dictionaries to single ...

What is suggested seed value to use with random.seed()?

Simple enough question: I m using python random module to generate random integers. I want to know what is the suggested value to use with the random.seed() function? Currently I am letting this ...

How can I make the PyDev editor selectively ignore errors?

I m using PyDev under Eclipse to write some Jython code. I ve got numerous instances where I need to do something like this: import com.work.project.component.client.Interface.ISubInterface as ...

How do I profile `paster serve` s startup time?

Python s paster serve app.ini is taking longer than I would like to be ready for the first request. I know how to profile requests with middleware, but how do I profile the initialization time? I ...

Pragmatically adding give-aways/freebies to an online store

Our business currently has an online store and recently we ve been offering free specials to our customers. Right now, we simply display the special and give the buyer a notice stating we will add the ...

Converting Dictionary to List? [duplicate]

I m trying to convert a Python dictionary into a Python list, in order to perform some calculations. #My dictionary dict = {} dict[ Capital ]="London" dict[ Food ]="Fish&Chips" dict[ 2012 ]="...

热门标签