解析ISO网站单个标准的静态网址

import sys

import os

sys.path.insert(0, os.path.join(os.path.dirname(file), 'lib'))

import requests

from bs4 import BeautifulSoup

url = "https://www.iso.org/standard/45780.html"

print(f"查询网址:{url}")

headers = {

"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36",

"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,/ ;q=0.8",

"Accept-Language": "zh-CN,zh;q=0.9,en;q=0.8",

"Accept-Encoding": "gzip, deflate, br",

"Referer": "https://www.iso.org/",

"Connection": "keep-alive",

"Upgrade-Insecure-Requests": "1"

}

response = requests.get(url, headers=headers)

html_content = response.text

with open('page.html', 'w', encoding='utf-8') as f:

f.write(html_content)

soup = BeautifulSoup(html_content, 'html.parser')

standard_number = soup.find(class_='standard-number')

standard_title = soup.find(class_='standard-title')

print(standard_number.text.strip() + " " + standard_title.text.strip())

description = soup.find(itemprop='description')

if description:

print(f"摘要内容:")

spans = description.find_all('span', lang='EN-GB')

for span in spans:

print(span.text.strip())

lifecycle = soup.find(class_='lifecycle')

if lifecycle:

print(f"版本替代关系:")

steps = lifecycle.find_all(class_='step-item')

for step in steps:

print(f"{step.text.strip()}")

相关推荐
杨杨杨大侠7 小时前
Jev、Kev、Laya:决策模型怎么选,什么时候需要微调?
人工智能·python·agent
LOVE️YOU8 小时前
Python 在定义函数时,究竟定义的是什么?
python
段一凡-华北理工大学8 小时前
大模型应用开发 100 天:Python + LLM 从入门到精通 day26~Prompt 调试与优化——A/B 测试与效果评估
windows·python·大模型·prompt·智能体·提示词工程·高炉智能化
Minecraft红客8 小时前
以撒的结合
python·游戏·电脑·娱乐
Circ.8 小时前
Python 调试 Litellm 本地大模型接口:模型列表与对话接口实操踩坑记录
开发语言·python
风早爽太9 小时前
用 ‌Render‌ 快速部署网站和常见问题解决
python·fastapi
李航198310 小时前
给自己的图形引擎,配上了AI渲染,做设计真是太方便了
人工智能·python·计算机视觉·ai·ai编程
L@ncor10 小时前
第六章 框架开发实践 · 学习笔记(AutoGen / AgentScope / CAMEL / LangGraph)
python·框架·autogen·langgraph·agentscope
Zhou14113610 小时前
SpringSecurity_02_授权与高级功能
开发语言·python
摇滚侠12 小时前
《On Java 中文版 基础卷》阅读笔记 对象无处不在 03
java·笔记·python