python - 为什么我在 HTML 标签之间没有得到任何内容?
问题描述
我正在尝试从该网站“ https://www.physiotherapyexercises.com/ ”中提取数据。但是当我运行以下代码时,我只得到了 html 正文,没有得到 HTMl 标签之间的内容。
import requests
import bs4
url = "https://www.physiotherapyexercises.com/"
res = requests.get(url)
soup = bs4.BeautifulSoup(res.text, 'lxml')
print(soup)
解决方案
您正在搜索的数据是使用 Javascript 从其他位置加载的。您可以使用requests
//模块来获取信息re
。json
例如:
import re
import json
import requests
url = 'https://www.physiotherapyexercises.com/Js/Data/ExerciseData_English_2019_12_06_00_49_56.js'
data = json.loads(re.search(r'exerciseRecords=(.*?]);', requests.get(url).text).group(1))
# uncomment this to print all data:
# print(json.dumps(data, indent=4))
for exercise in data:
print(*exercise['Texts'], sep='\n')
print('-' * 80)
印刷:
...
Strength - knee - flexors - wall mounted pulleys - prone.
Knee flexor strengthening in prone using pulleys
To strengthen the knee flexors.
To strengthen the muscles at the back of your thigh.
Position the patient in prone facing away from the pulleys. Adjust the pulley system so that the direction of pull opposes knee flexion. Instruct the patient to flex their knee.
Position yourself lying on your stomach. Adjust the pulley system so that the direction of pull is towards the top of the bed. Start with your knee straight and leg resting on the bed. Finish with your knee bent.
More advanced: 1. Progress using strength training principles.
--------------------------------------------------------------------------------
Strength - knee - flexors - theraband - prone.
Knee flexor strengthening in prone using theraband
To strengthen the knee flexors.
To strengthen the muscles at the back of your thigh.
Position the patient in prone with their knee extended. Adjust the theraband so that the direction of pull opposes knee flexion. Instruct the patient to flex their knee.
Position yourself lying on your stomach. Adjust the theraband so that the direction of pull is towards the top of the bed. Start with your knee straight and leg resting on the bed. Finish with your knee bent.
Less advanced: 1. Downgrade the colour of the theraband. More advanced: 1. Upgrade the colour of the theraband.
... and so on.
推荐阅读
- javascript - 画布性能图块集渲染
- r - 试图将数据写入 newick 格式 R
- django - Django 更改文件未同步 ubuntu nginx gunicorn 上的更改
- sql - BigQuery 中的动态条件联接
- node.js - Express-validator:我们如何验证对象键?
- javascript - 为什么我会得到“在 'Window' 上执行 'postMessage' 失败:#
使用 iframe 的 Promise 时无法克隆错误”? - python - 如何使用 numpy "allclose" 返回一个公共值数组?
- json - 如何使用 groovy 将 json 数据元素解析为域对象
- php - 有没有更好的方法在php中按星期几排序和显示日期数组?
- css - 如何更改引导程序表单中日期选择器/日历图标的位置?