I am trying to post a request to the telegra.ph api(一个简单的在线发布工具)。为了编辑页面内容,我使用的是python requests
。从我从api文档中获得的示例代码,到目前为止我已经:
import requests
params = {
'path': '/mypage',
'title': 'My Title',
'content':[{"tag":"p","children":["WHAT IS GOING ON"]}],
'author_name': 'My Name',
'author_url': None,
'return_content': 'true'
}
url = 'https://api.telegra.ph/editPage'
r = requests.post(url, json=params)
r.raise_for_status()
response = r.json()
非常简单的代码,它工作正常。我的问题是,我现在想添加一个指向我内容的链接。我尝试将代码从"p"
更改为"a"
,但结果页面中根本没有标记。有谁知道他们的内容使用的格式,以及如何将段落标记更改为链接标记?
答案 0 :(得分:1)
我用它来创建一个带有链接的页面:
import requests
params = {
'access_token': "",
'path': '/mytestpage',
'title': 'My Title',
'content':[ {"tag":"p","children":["A link to Stackoverflow ",{"tag":"a","attrs":{"href":"http://stackoverflow.com/","target":"_blank"},"children":["http://stackoverflow.com"]}]} ],
'author_name': 'My Name',
'author_url': None,
'return_content': 'true'
}
url = 'https://api.telegra.ph/createPage'
r = requests.post(url, json=params)
r.raise_for_status()
response = r.json()
print response
你应该可以为editPage做类似的事情。
提示:您可以使用Postman或Chrome开发工具之类的东西来确定使用telegra.ph用户界面发布的内容。