解析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()}")

相关推荐
安_1 小时前
如何构建和使用向量索引?HNSW 和 IVF 有什么区别?
python·ai
counting money3 小时前
Java IO流详解:从InputStream到文件操作实战
java·开发语言·python
坚持学习前端日记3 小时前
Python SQLAlchemy ORM 从0到1精通实战手册(基础到复杂高阶)
数据库·python·oracle
北斗落凡尘4 小时前
LangGraph 入门实战(11)--输出模式
后端·python·langchain
雪碧聊技术4 小时前
安装Python(保姆级教程)
python·版本更新·python下载
++==4 小时前
JSON和Python的 四种核心容器
python·json
张龙6876 小时前
uv 全面指南:比 pip 快 100 倍的 Python 包管理器,从安装到团队落地
后端·python
@HNUSTer7 小时前
Python数据可视化科技图表绘制系列教程(八)
python·数据可视化·科技论文·专业制图·科研图表
专注仿真8 小时前
问答大模型技术方案算法实现-熵权法融合算法 + 交叉编码器重排算法
人工智能·python·算法·语言模型·问答大模型关键算法·熵权融合算法·交叉编码器重排算法
满怀冰雪9 小时前
22-使用 PaddleClas 快速训练图像分类模型
人工智能·python·机器学习·分类·数据挖掘·paddlepaddle