def GetQuoraComments(html): from urllib.request import urlopen from bs4 import BeautifulSoup html = urlopen(html) bs = BeautifulSoup(html, 'html.parser') search=bs.find_all('span') comments=[] for item in search: bsp=BeautifulSoup(str(item), 'html.parser') comment_parts=bsp.find_all('p',{'class','ui_qtext_para u-ltr u-text- align--start'}) if len(comment_parts)>0: comments += ['\n'.join(['\t'+x.get_text() for x in comment_parts])] print(len(comments),' comments fetched.') return comments
Допустим, я передал "https://www.quora.com/16-Pizzas-are-ordered-for-the-children-at-a-party-Each-pizza-is-cut-into-8-equal-slices-Each-child-eats-2-slices-There-are-4-slices-left-How-many-children-are-at-the-party" в своей функции. Я должен получить более 100 комментариев, но я получаю примерно около 8.