如何从通过 Javascript 加载的页面上 __scrape__ 数据

2023-12-28

我想使用 beautifulsoup 刮掉此页面上的评论 - https://www.x....s.com/video_id/the-suburl

评论通过 JavaScript 在点击时加载。评论是分页的,每个页面也会在点击时加载评论。我希望获取所有评论,对于每条评论,我想获取海报个人资料网址、评论、编号。喜欢的数量、不喜欢的数量以及发布的时间(如页面上所述)。

注释可以是字典列表。

我该怎么办?


该脚本将打印页面上找到的所有评论:

import json
import requests
from bs4 import BeautifulSoup


url = 'https://www.x......com/video_id/gggjggjj/'
video_id = url.rsplit('/', maxsplit=2)[-2].replace('video', '')

u = 'https://www.x......com/threads/video/ggggjggl/{video_id}/0/0'.format(video_id=video_id)
comments = requests.post(u, data={'load_all':1}).json()

for id_ in comments['posts']['ids']:
    print(comments['posts']['posts'][id_]['date'])
    print(comments['posts']['posts'][id_]['name'])
    print(comments['posts']['posts'][id_]['url'])
    print(BeautifulSoup(comments['posts']['posts'][id_]['message'], 'html.parser').get_text())
    # ...etc.
    print('-'*80)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何从通过 Javascript 加载的页面上 __scrape__ 数据 的相关文章

随机推荐