[英]Disqus - change this.page.identifier but keep all comments
[英]Retrieving comments (disqus) embedded in another web page with python
我正在使用python 3.5(Beautifulsoup)抓取一个网站。 我可以阅读源代码中的所有内容,但一直在尝试从Disqus中检索嵌入的注释,但都没有成功(这是对脚本的引用)。
该段html代码源如下所示:
var disqus_identifier = "node/XXXXX";
script type='text/javascript' src='https://disqus.com/forums/siteweb/embed.js';
src发送到脚本功能。
我已经阅读了使用硒的stackoverflow中的建议,但是我很难使它成功。 我了解硒模拟了浏览器(我认为它对于我想要的东西来说太重了)。 但是,我的webdrivers有问题,它不能正常工作。 因此,我放弃了此选项。
我希望能够执行脚本并检索带有注释的.js。 我发现可能的解决方案是PyV8。 但是我不能导入python。 我在互联网上阅读了帖子,我用Google搜索了它,但是它不起作用。
我安装了Sublime Text 3,并在以下位置手动下载了pyv8-win64-p3:
C:\\ Users \\ myusername \\ AppData \\ Roaming \\ Sublime Text 3 \\ Installed Packages \\ PyV8 \\ pyv8-win64-p3
但我不断得到:
ImportError:没有名为“ PyV8”的模块。
如果有人可以帮助我,我将非常感激。
因此,您可以通过研究网络流量来构造Disqus API。 页面源中包含所有必需的数据。 像Disqus API发送一些查询字符串。 最近,我从Disqus API中提取了注释,这是示例代码。
示例:这里汤-页面源代码和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,您可以在其中提取注释的地方找到注释。 希望这对您有帮助。
对于Facebook嵌入的注释,您可以使用Facebook的graph api提取json格式的注释。
例-
Facebook评论-https: https://graph.facebook.com/comments/?ids= "link of page"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.