解析ISO网站单个标准的静态网址

解析ISO网站单个标准的静态网址
import sysimport ossys.path.insert(0, os.path.join(os.path.dirname(file), ‘lib’))import requestsfrom bs4 import BeautifulSoupurl “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/xhtmlxml,application/xml;q0.9,image/avif,image/webp,image/apng,/;q0.8”,“Accept-Language”: “zh-CN,zh;q0.9,en;q0.8”,“Accept-Encoding”: “gzip, deflate, br”,“Referer”: “https://www.iso.org/”,“Connection”: “keep-alive”,“Upgrade-Insecure-Requests”: “1”}response requests.get(url, headersheaders)html_content response.textwith 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()})