import requests
from bs4 import BeautifulSoup
text = “BETC-HJ-2024-P-00362”
url = “http://weixin.cabr-betc.com/gjwx/wxfind/findreport?prtnum=”+text
print(url)
发送 GET 请求获取网页内容
response = requests.get(url)
使用 BeautifulSoup 解析网页内容
soup = BeautifulSoup(response.text, ‘html.parser’)
查找报告编号
report_num_elem = soup.find(‘div’, class_=‘weui-cell__hd’, string=‘报告编号’)
if report_num_elem is not None:
report_num = report_num_elem.find_next(‘div’, class_=‘weui-cell__bd’).text[38:]
print(f"报告编号: {report_num}")
else:
print(“未找到报告编号元素”)
查找报告标题
report_title_elem = soup.find(‘div’, class_=‘weui-cell__hd’, string=‘报告标题’)
if report_title_elem is not None:
report_title = report_title_elem.find_next(‘div’, class_=‘weui-cell__bd’).text[38:]
print(f"报告标题: {report_title}")
else:
print(“未找到报告标题元素”)
查找委托单位
entrust_unit_elem = soup.find(‘div’, class_=‘weui-cell__hd’, string=‘委托单位’)
if entrust_unit_elem is not None:
entrust_unit = entrust_unit_elem.find_next(‘div’, class_=‘weui-cell__bd’).text[38:]
print(f"委托单位: {entrust_unit}")
else:
print(“未找到委托单位元素”)
查找样品名称
sample_name_elem = soup.find(‘div’, class_=‘weui-cell__hd’, string=‘样品名称’)
if sample_name_elem is not None:
sample_name = sample_name_elem.find_next(‘div’, class_=‘weui-cell__bd’).text[38:]
print(f"样品名称: {sample_name}")
else:
print(“未找到样品名称元素”)
查找规格型号和数量(假设它们在同一行显示)
spec_quantity_elem = soup.find(‘div’, class_=‘weui-cell__hd’, string=‘规格型号’)
if spec_quantity_elem is not None:
spec_quantity = spec_quantity_elem.find_next(‘div’, class_=‘weui-cell__bd’).text[38:]
print(f"规格型号和数量: {spec_quantity}")
else:
print(“未找到规格型号和数量元素”)
查找检验项目
test_items_elem = soup.find(‘div’, class_=‘weui-cell__hd’, string=‘检验项目’)
if test_items_elem is not None:
test_items = test_items_elem.find_next(‘div’, class_=‘weui-cell__bd’).text[38:]
print(f"检验项目: {test_items}")
else:
print(“未找到检验项目元素”)
查找报告日期
report_date_elem = soup.find(‘div’, class_=‘weui-cell__hd’, string=‘报告日期’)
if report_date_elem is not None:
report_date = report_date_elem.find_next(‘div’, class_=‘weui-cell__bd’).text[38:]
print(f"报告日期: {report_date}")
else:
print(“未找到报告日期元素”)
查找报告状态
report_status_elem = soup.find(‘div’, class_=‘weui-cell__hd’, string=‘报告状态’)
if report_status_elem is not None:
report_status = report_status_elem.find_next(‘div’, class_=‘weui-cell__bd’).text[38:]
print(f"报告状态: {report_status}")
else:
print(“未找到报告状态元素”)