从评论部分检索文本?

时间:2020-06-27 18:44:55

标签: python

我正在尝试从注释部分检索文本,但是不确定为什么此代码只能运行一次。有人遇到过类似的问题吗?

import requests
from requests import get
from bs4 import BeautifulSoup
import numpy as np

results = requests.get("https://www.reddit.com/r/RobinHoodPennyStocks/comments/hegob7/no_body_liked_my_post_last_time_but_its_mooning/")

soup = BeautifulSoup(results.text, "html.parser")

comments = [] 

comments_div = soup.find_all('div', class_='_3cjCphgls6DH-irkVaA0GM')

for container in comments_div:

  name = container.p.text

  comments.append(name)

print(comments)

0 个答案:

没有答案