【发布时间】:2021-06-22 20:50:10
【问题描述】:
我正在尝试在 DataFrame 中获取此 url = "https://www.timeshighereducation.com/world-university-rankings/2020/subject-ranking/life-sciences#!/page/0/length/25/sort_by/rank/sort_order/asc/cols/stats" 中的所有表(总共 821 行,需要所有表)。我使用的代码是这样的:
import requests
from bs4 import BeautifulSoup
import json
url = "https://www.timeshighereducation.com/world-university-rankings/2020/subject-ranking/life-sciences#!/page/0/length/25/sort_by/rank/sort_order/asc/cols/stats"
r = requests.get(url)
soup = BeautifulSoup(r.content, 'html.parser')
print(soup) # It doesn't print anything
我的想法是获取汤中的信息,然后查找标签<script> jQuery.extend(Drupal.settings, {"basePath": ... 并进入followig json 链接https://www.timeshighereducation.com/sites/default/files/the_data_rankings/life_sciences_rankings_2020_0__a2e62a5137c61efeef38fac9fb83a262.json 表中的所有数据在哪里。我已经有了读取这个json链接的功能,但首先需要在soup中找到信息,然后获取json链接。需要以这种方式,因为我必须阅读许多表并通过手动检查来获取 json 链接,这对我来说不是一个选择。
【问题讨论】:
标签: python json beautifulsoup html-parsing