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

相关推荐
智能体与具身智能11 小时前
TVA具身智能的概念、架构与应用(19)
人工智能·python·具身智能
2601_9622946112 小时前
python中range函数怎么用
python·for循环·可迭代对象·range函数·整数列表
青 春 记 忆13 小时前
零基础入门python70:Docker Compose 编排完整后端
python·后端开发
新时代牛马13 小时前
字符设备驱动完整篇:从 cdev_add、file_operations 到chrdev_open 与排障
开发语言·python
白山编程大哥14 小时前
Java OutputStreamWriter 详解:从字符到字节的桥梁
java·开发语言·python
落羽的落羽14 小时前
【AI】快速理解AI应用的相关名词概念
linux·c++·人工智能·python·计算机网络·算法
Chasing__Dreams14 小时前
大模型应用开发--13--RAG 查询优化策略
python
“AI国潮设计-小江”15 小时前
《Python实战 | SDXL大模型批量生成“英歌舞海浪”蛋糕IP,附核心Prompt控制代码与IP授权变现思路》
人工智能·python·prompt·aigc
znnnk15 小时前
【Python】GUI 开发从入门到实战(三):PyQt/PySide 进阶之路
开发语言·python·pyqt
触底反弹17 小时前
面试被问到 Text2SQL,我用 DeepSeek 自己实现了一个
python·sqlite