我試圖解析從本網站鏈接的意見「查看更多」選項數據: I need to get 1000 comments, by default it shows only 10如何颳去網站有使用BeautifulSoup圖書館在Python
我想1000層的意見,這表明只有10默認。我無法想出一個辦法,點擊「查看更多」
後能得到它顯示在網頁上的內容,我有以下代碼uptil現在:
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))
你是如何試圖點擊「查看更多」 ......硒,或者是你抓住「下一步」 href和直接請求頁面? – pbuck