Skip to content

Web crawling (or data crawling) is used for data extraction and refers to collecting data from either the world wide web or, in data crawling cases – any document, file, etc . Traditionally, it is done in large quantities. Therefore, usually done with a crawler agent.

Notifications You must be signed in to change notification settings

nxhawk/Crawl-Data-Python

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 

Repository files navigation

Crawl dữ liệu với python

Xin chào mọi người,

Trong bài viết này, mình xin trình bày cách lấy dữ liệu trong một trang web với python.

1. Cài đặt các thư viện

Đầu tiên bạn cần phải cài sẵn thư viện sau về máy tính.

#Install requests để thực hiện gửi yêu cầu đến trang web cần data
pip install requests

Tiếp theo truy cập vào trang web bạn muốn lấy dữ liệu, ở đây mình lấy dữ liệu từ trang https://goctruyentranhhay.com

2. Lấy dữ liệu thô của trang web

Sử dụng F12/Fn+F12 hoặc click chuột trái chọn Inspect (Kiểm tra) để mở cửa sổ Kiểm tra phần tử

Tại cửa sổ này, ta chọn đến Network -> Fetch/XHR rồi reload lại trang để gửi lại HTTP request (xem hình minh họa)

image

Tiếp theo ta double click vào new?p=0, sẽ mở ra một tab mới như hình bên dưới

image

Nếu muốn dễ nhìn như hình bạn cần cài thêm một extension cho trình duyệt chrome tại đây

3. Phân tích dữ liệu

Như hình trên, để lấy được dữ liệu tên truyện ta chỉ cần truy cập đến trường name trong result/data

Để ý thêm tại đường link trang API chỉ cần thay đổi số sau /new?p= thì ta có dữ liệu trang tiếp theo.

4. Tổng kết

Ý tưởng cơ bản là như vậy, bạn đọc hãy nghiên cứu code nhé <(^-^)>.

Bài viết còn rất lủng củng, mong mọi người thứ lỗi.

Damn!!! Wibu is the best

image

About

Web crawling (or data crawling) is used for data extraction and refers to collecting data from either the world wide web or, in data crawling cases – any document, file, etc . Traditionally, it is done in large quantities. Therefore, usually done with a crawler agent.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages