Untitled

mail@pastecode.io avatar
unknown
plain_text
7 months ago
767 B
3
Indexable
Never
import requests
from bs4 import BeautifulSoup
import re

def get_info_by_id(ID):
    url = f"https://diemthi.vnexpress.net/index/detail/sbd/{ID}/year/2023"
    response = requests.get(url)
    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}'


Id_01 = "03000002"  
print(get_info_by_id(Id_01))

print()
Id_02 = "12002202"
print(get_info_by_id(Id_02))