python urllib2调用简单的机器论坛api

时间:2015-03-11 06:06:59

标签: php python urllib2

请在下面找到代码

import urllib2
post_id = raw_input('Please enter Id of the post to be migrated : ')
smf_url = 'www.simplemachines.org/community/index.php?topic=%s&action=.xml' %(post_id)
req = urllib2.Request(smf_url)
response = urllib2.urlopen(req)
the_page = response.read()

当我删除action=.xml时,我会在浏览器中获取正确的html内容以获取主题ID。当我想要获取xml feed时,大多数时候它都会给我错误的数据。

任何人都可以告诉我是否应该传递任何其他查询参数。感谢

1 个答案:

答案 0 :(得分:1)

尝试一下:https://github.com/bithon/python-simplemachinesforum

from simplemachinesforum.simplemachinesforum import SimpleMachinesForum

smf_url = "https://www.any-simplemachinesforum.com"
smf_user = "user_name"
smf_pass = "password"
smf = SimpleMachinesForum(smf_url, smf_user, smf_pass)

# 1 = board id:
smf.new_topic(1, "subject", "This is the message to post!")