我正在尝试分析来自此网站链接的评论: I need to get 1000 comments, by default it shows only 10
我想得到1000条评论,默认情况下只显示10条。单击“查看更多”后,我无法找到获取显示在网页上的内容的方法
我现在有以下代码正常运行:
import urllib.request
from bs4 import BeautifulSoup
import sys
non_bmp_map = dict.fromkeys(range(0x10000, sys.maxunicode + 1), 0xfffd)
response = urllib.request.urlopen("https://www.mygov.in/group-issue/share-
your-ideas-pm-narendra-modis-mann-ki-baat-26th-march-2017/")
srcode = response.read()
soup = BeautifulSoup(srcode, "html.parser")
all_comments_div=soup.find_all('div', class_="comment_body");
all_comments=[]
for div in all_comments_div:
all_comments.append(div.find('p').text.translate(non_bmp_map))
print (all_comments)
print (len(all_comments))
您可以使用while循环来获取下一页
(即有下一页,所有评论少于1000条)
新的注释通过
ajax
加载,我们需要解析它,然后使用bs
,即:输出:
^{pr2}$相关问题 更多 >
编程相关推荐