我正在try 从这个网址解析页面: https://www.mathworks.com/help/radar/referencelist.html?type=block

我需要从"Radar Deliver-Blocks"标题下的区块列表中获取所有链接,即<div id="reflist_content">内.

我这样使用requests_html个:

from requests_html import HTMLSession

session = HTMLSession()

url = 'https://www.mathworks.com/help/radar/referencelist.html?type=block'
r = session.get(url)

r.html.arender()

results = r.html.find('div')
res_str = ''

for item in results:
    #print(item)
    #print(item.text)
    res_str += str(item) + '\n'
    res_str += item.text + '\n\n'

结果中reflist_content的文本为空.

我在结果中找不到任何所需的内容.我try 通过不同的html标签或关键词进行搜索,但似乎带有块的表格根本没有呈现. 我做错了什么?

推荐答案

您看到的数据从外部URL加载.要加载它,您可以使用以下示例:

import requests
from bs4 import BeautifulSoup

url = "https://www.mathworks.com/help/radar/referencelist_block_cat.xml"

soup = BeautifulSoup(requests.get(url).content, "xml")

for category in soup.select("cat:has(ref)"):
    print(category.title.text)
    print()
    for r in category.select("ref"):
        print(
            f'{r.text[:40]:<40} {"https://www.mathworks.com/help/radar/" + r["target"]}'
        )
    print()

输出:

Radar Toolbox

Backscatter signals from bicyclist (Sinc https://www.mathworks.com/help/radar/ref/backscatterbicyclistblock.html
Backscatter signals from pedestrian (Sin https://www.mathworks.com/help/radar/ref/backscatterpedestrianblock.html
Barrage jammer interference source (Sinc https://www.mathworks.com/help/radar/ref/barragejammer.html
Constant gamma clutter simulation (Since https://www.mathworks.com/help/radar/ref/constantgammaclutter.html
Constant gamma clutter simulation using  https://www.mathworks.com/help/radar/ref/gpuconstantgammaclutter.html
Generate radar sensor detections and tra https://www.mathworks.com/help/radar/ref/radardatagenerator.html
Combine detection reports from different https://www.mathworks.com/help/radar/ref/detectionconcatenation.html
Two-ray channel environment (Since R2021 https://www.mathworks.com/help/radar/ref/tworaychannel.html
Wideband two-ray channel environment (Si https://www.mathworks.com/help/radar/ref/widebandtworaychannel.html
Library of pulse waveforms (Since R2021a https://www.mathworks.com/help/radar/ref/pulsewaveformlibrary.html
Library of pulse compression specificati https://www.mathworks.com/help/radar/ref/pulsecompressionlibrary.html
Cluster detections (Since R2021a)        https://www.mathworks.com/help/radar/ref/dbscanclusterer.html

Data Synthesis

Backscatter signals from bicyclist (Sinc https://www.mathworks.com/help/radar/ref/backscatterbicyclistblock.html
Backscatter signals from pedestrian (Sin https://www.mathworks.com/help/radar/ref/backscatterpedestrianblock.html
Barrage jammer interference source (Sinc https://www.mathworks.com/help/radar/ref/barragejammer.html
Constant gamma clutter simulation (Since https://www.mathworks.com/help/radar/ref/constantgammaclutter.html
Constant gamma clutter simulation using  https://www.mathworks.com/help/radar/ref/gpuconstantgammaclutter.html
Generate radar sensor detections and tra https://www.mathworks.com/help/radar/ref/radardatagenerator.html
Combine detection reports from different https://www.mathworks.com/help/radar/ref/detectionconcatenation.html
Two-ray channel environment (Since R2021 https://www.mathworks.com/help/radar/ref/tworaychannel.html
Wideband two-ray channel environment (Si https://www.mathworks.com/help/radar/ref/widebandtworaychannel.html
Library of pulse waveforms (Since R2021a https://www.mathworks.com/help/radar/ref/pulsewaveformlibrary.html

Signal and Data Processing

Library of pulse compression specificati https://www.mathworks.com/help/radar/ref/pulsecompressionlibrary.html
Cluster detections (Since R2021a)        https://www.mathworks.com/help/radar/ref/dbscanclusterer.html

Detection, Range, Angle, and Doppler Estimation

Library of pulse compression specificati https://www.mathworks.com/help/radar/ref/pulsecompressionlibrary.html

Clustering

Cluster detections (Since R2021a)        https://www.mathworks.com/help/radar/ref/dbscanclusterer.html

Python相关问答推荐

如何强制cv2.electrical画顺时针弧线?

产生镜像输出的MSG算法输出

使用pandas MultiIndex进行不连续 Select

如何计算部分聚合数据的统计数据

保留包含pandas pandras中文本的列

Plotly:如何更改Heatmap中彩色条的勾选文本

Pandas :多索引组

无法使用equals_html从网址获取全文

如何使用Jinja语法在HTML中重定向期间传递变量?

使用Keras的线性回归参数估计

Pandas 第二小值有条件

使用SciPy进行曲线匹配未能给出正确的匹配

删除任何仅包含字符(或不包含其他数字值的邮政编码)的观察

将输入管道传输到正在运行的Python脚本中

迭代嵌套字典的值

Pandas Loc Select 到NaN和值列表

python中的解释会在后台调用函数吗?

如何合并两个列表,并获得每个索引值最高的列表名称?

如何在Python中使用Pandas将R s Tukey s HSD表转换为相关矩阵''

Geopandas未返回正确的缓冲区(单位:米)