因此,您可以通过研究其网络流量来构建 Disqus API;在页面源中存在所有必需的数据。像 Disqus API 发送一些查询字符串。最近我从 Disqus API 中提取了评论,这里是示例代码。
示例:Here soup - 页面源和params_dict = json.loads(str(soup).split("embedVars = ")[1].split(";")[0])
def disqus(params_dict,soup):
headers = {
'User-Agent':'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:44.0) Gecko/20100101 Firefox/44.0'
}
comments_list = []
base = 'default'
s_o = 'default'
version = '25916d2dd3d996eaedf6cdb92f03e7dd'
f = params_dict['disqusShortname']
t_i = params_dict['disqusIdentifier']
t_u = params_dict['disqusUrl']
t_e = params_dict['disqusTitle']
t_d = soup.head.title.text
t_t = params_dict['disqusTitle']
url = 'http://disqus.com/embed/comments/?base=%s&version=%s&f=%s&t_i=%s&t_u=%s&t_e=%s&t_d=%s&t_t=%s&s_o=%s&l='%(base,version,f,t_i,t_u,t_e,t_d,t_t,s_o)
comment_soup = getLink(url)
temp_dict = json.loads(str(comment_soup).split("threadData\" type=\"text/json\">")[1].split("</script")[0])
thread_id = temp_dict['response']['thread']['id']
forumname = temp_dict['response']['thread']['forum']
i = 1
count = 0
flag = True
while flag is True:
disqus_url = 'http://disqus.com/api/3.0/threads/listPostsThreaded?limit=100&thread='+thread_id+'&forum='+forumname+'&order=popular&cursor='+str(i)+':0:0'+'&api_key=E8Uh5l5fHZ6gD8U3KycjAIAk46f68Zw7C6eW8WSjZvCLXebZ7p0r1yrYDrLilk2F'
comment_soup = getJson(disqus_url)
它会返回 json,您可以在其中找到可以提取评论的评论。希望这对您有所帮助。