Untitled
unknown
python
a year ago
1.0 kB
4
Indexable
import requests from bs4 import BeautifulSoup import re def get_info_by_id(ID): try: url = f"https://diemthi.vnexpress.net/index/detail/sbd/{ID}/year/2023" response = requests.get(url) response.raise_for_status() soup = BeautifulSoup(response.content, "html.parser") info_detail = str(soup.find("p", class_="o-detail-thisinh__cumthi")) ma_vung_thi = re.findall(r'\s+(\d+.+)(</p>)', info_detail)[0][0] diem_elements = soup.findAll("div", class_="o-detail-thisinh__diemthi") diem_element = diem_elements[0] diem = diem_element.text.strip() diem = re.sub(r'\s+', ' ', diem) return f'Mã Vùng Thi: {ma_vung_thi}\n{diem}' except requests.exceptions.RequestException as e: return f"Lỗi khi truy cập: {e}" except Exception as e: return f"Lỗi không xác định: {e}" id_01 = "12002202" print(get_info_by_id(id_01)) id_02 = "12345" print(get_info_by_id(id_02))
Editor is loading...