# Bài học đầu tiên Yêu cầu 1: Viết một http request đơn giản, gửi get request lên 1 url bài nhạc mp3, sử dụng thư viện requests của python -> trả về html của trang đó 1. Đầu tiên, cài thư viện requests trước: ``` pip install requests ``` 2. Và sau đó: ``` import requests r = requests.get("https://zingmp3.vn/album/Nhac-Lofi-Chill-Gay-Nghien-Khai-Dang-Hoai-Lam-Freak-D-Phan-Duy-Anh/6BCAUIEO.html" print(r.text) ``` 3.Kết quả trả về: ![image](https://hackmd.io/_uploads/r14KHG46p.png) Done! Yêu cầu 2: Thêm headers tên là abc: test và sửa user-agent thành aaa [reference link](https://webhook.site/?fbclid=IwAR2SEPtQEhCaEvsFoW74IZgx_XscU_Z2x7L3CO9TkvyPNviR8Rf1-wEu8XU#!/view/c0d85f3e-87a0-4d0d-86cb-2fa26792b9f5) -> Vào trang này sẽ thấy 1 webhook của mình rồi xem thông tin... 1. Inspect -> Network sau đó reload page để lấy thông tin ![image](https://hackmd.io/_uploads/S1vx_MNTp.png) 2. Thêm phần Header và sửa user-agent ``` import requests url = "https://webhook.site/#!/view/e2cf86b3-2b3a-4904-b617-3fa9873d3ee3/abf78bd1-253f-471f-8ff5-cb15cacc4265/1" headers = { 'abc': 'test', 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36 Edg/122.0.0.0' } new_user_agent = 'aaa' headers['User-Agent'] = new_user_agent x = requests.post(url, headers=headers) print(x) ``` 3. Kết quả: Response 403 :-1:
{"title":"Bài học đầu tiên","description":"Bài học đầu tiên******","contributors":"[{\"id\":\"fb466029-aace-415a-bc61-a0c20b37ca19\",\"add\":1396,\"del\":1}]"}
Expand menu