【发布时间】:2021-08-09 22:51:37
【问题描述】:
我正在编写一个代码来抓取https://www.metacritic.com/game/playstation-4/red-dead-redemption-2/user-reviews的所有评论。
由于长 cmets 出现“展开”按钮,我在 抓取 cmets 时遇到了困难。
我已设法刮取长 cmets,但无法刮取所有其他的:
review <- html_text(html_nodes(webpage,'span[class="blurb blurb_expanded"]'))
我找到了一个使用 Beautifulsoup 的代码,但在 Rvest 上做同样的事情却一无所知
if review.find('span', class_='blurb blurb_expanded'):
review_dict['review'].append(review.find('span', class_='blurb blurb_expanded').text)
else:
review_dict['review'].append(review.find('div', class_='review_body').find('span').text)
你如何在 Rvest 上做类似的事情?您如何为要 scrape 的内容添加条件?您如何刮取所有未扩展的 cmets?
谢谢!!
【问题讨论】:
-
包括评论家的评论?
-
仅供参考,它是 scrape(和 scraping、scraped、scraper)不是废品。 “废弃”意味着像垃圾一样扔掉:-(
-
哈哈谢谢! @balmy
标签: r web-scraping conditional-statements