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