Python URLlib2 调用简单机器论坛 API


python urllib2 call to simple machine forum api

请在下面找到代码

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提要时,大多数时候它给了我错误的数据。

任何人都可以让我知道我是否应该传递任何其他查询参数。谢谢

试试这个: 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!")