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

相关推荐
我就是不信几秒前
Java8 lambda 表达式 forEach 如何提前终止?
开发语言·windows·python
全栈弄潮儿8 分钟前
Python实战第9期:文件操作
后端·python·编程语言
小星星_ios12 分钟前
从 3Blue1Brown 到 NumPy:手写一个神经网络训练 MNIST
人工智能·python·神经网络
Maxwin16 分钟前
Manim 竖屏画布选 9×16 还是 4.5×8?从 font_size 和每单位像素数说起
python·ffmpeg
昭昭日月明23 分钟前
使用 Ragas 量化 RAG
python·langchain·ai编程
姜九笙56128 分钟前
python学习---归来仍是新人
java·python·学习
幸福清风44 分钟前
从域名到一行 nginx 配置:一次站点 HTTPS 证书更换与排障复盘
python·nginx·https
云水初1 小时前
【agent篇】RAG Agent避坑指南(附高级RAG Agent汇总)
开发语言·笔记·python·学习·langchain·agent·rag
薛定猫AI1 小时前
【技术干货】多AI团队大模型协作编排与编程项目评测架构解析
python·机器学习·ai·大模型·技术实战
外收内放1 小时前
数据分析(图表信息详解)
python·学习·数据分析·matplotlib