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

相关推荐
Java面试题总结2 小时前
Python 开发技巧 · 高级装饰器 —— 从基础到工业级实战
开发语言·python
纸小铭2 小时前
[MAF预定义ChatClient中间件-01]LoggingChatClient——在调用LLM前后输出日志
python·中间件·flask
aiqianji2 小时前
有哪些支持长文的AI生成短篇小说软件?
人工智能·python
狗都不学爬虫_3 小时前
AI逆向 - 某定制瑞树6纯算(ck-header-params后缀)
爬虫·python·网络爬虫
三十岁老牛再出发3 小时前
07.08.&07.09.每日总结
c语言·python
奇牙coding1233 小时前
OpenAI Realtime API WebSocket 断连 4008/1006 怎么解决?不是 Key 失效,是实时多模态独有的会话超时规则
python·websocket·网络协议·ai
齐 飞3 小时前
Python常用语法总结
python
齐 飞3 小时前
LangGraph快速入门-03节点与边
python·langchain
_Jimmy_3 小时前
Python 多线程使用和场景
python