You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用BeautifulSoup提取Sigma-Aldrich网页SVG内容失败,如何获取安全数据表PDF?

无法提取SVG中的安全数据表PDF链接

我尝试从Sigma-Aldrich的CAS号2127-03-9搜索页面抓取安全数据表(SDS)的PDF文件,发现PDF链接嵌套在页面的SVG内容中。参考相关网页抓取方案编写了BeautifulSoup代码,但代码无法提取SVG内容。

以下是我的代码:

base_url = 'https://www.sigmaaldrich.com/PK/en/search/2127-03-9?focus=products&page=1&perpage=30&sort=relevance&term=2127-03-9&type=cas_number'
headers = {"User-Agent": "Mozilla/5.0 (X11; CrOS x86_64 12871.102.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.141 Safari/537.36"}

with requests.Session() as session:
    # 提取SVG链接
    res = session.get(base_url, headers = headers)
    soup = BeautifulSoup(res.content, 'html.parser')
    svg = soup.select_one("object.svg-content")
    svg_link = urljoin(base_url, svg["data"])

运行代码时出现错误,错误截图如下:
错误截图

内容的提问来源于stack exchange,提问作者Muhammad Danish

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.24 23:24:56