Như chúng ta đã biết, Selenium là một công cụ tự động hóa dựa trên web giúp chúng ta tự động hóa các trình duyệt. Selenium là một công cụ thử nghiệm nguồn mở, có nghĩa là chúng tôi có thể dễ dàng tải xuống từ Internet và sử dụng nó. Với sự trợ giúp của selen, chúng tôi cũng có thể loại bỏ dữ liệu từ các trang web. Ở đây, trong bài viết này, chúng ta sẽ thảo luận về cách loại bỏ nhiều trang bằng Selenium. & NBSP; Show Có thể có nhiều cách để xóa dữ liệu từ các trang web, chúng tôi sẽ thảo luận về một trong số chúng. Vòng lặp qua số trang là cách đơn giản nhất để xóa dữ liệu. Chúng ta có thể sử dụng một bộ đếm gia tăng để thay đổi một trang sang trang khác. Như nhiều lần, vòng lặp của chúng tôi sẽ chạy, chương trình sẽ loại bỏ dữ liệu từ các trang web. URL trang đầu tiên: https://webscraper.io/test-sites/e-commerce/static/computers/laptops?page=1 Cuối cùng, các số trang duy nhất sẽ tăng lên như trang = 1, trang = 2 ngay bây giờ, hãy xem URL trang thứ hai.page=1, page=2… Now, Let see for second page URL. URL trang thứ hai: https://webscraper.io/test-sites/e-commerce/static/computers/laptops?page=2 Bây giờ, hãy để thảo luận về cách tiếp cận Installation: Bước đầu tiên của chúng tôi, trước khi viết một dòng mã duy nhất. Chúng tôi phải cài đặt selenium để sử dụng lớp WebDriver. Thông qua đó chúng tôi có thể khởi tạo các trình duyệt và nhận trang web từ URL được nhắm mục tiêu.selenium for using webdriver class. Through which we can instantiate the browsers and get the webpage from the targeted URL. pip install selenium Sau khi selen cài đặt thành công. Bây giờ, chúng tôi có thể đi đến bước tiếp theo để cài đặt gói tiếp theo của chúng tôi. & NBSP; Gói tiếp theo là WebDriver_Manager, hãy để cài đặt nó trước,webdriver_manager, Let install it first, pip install webdriver_manager Ừ! Chúng tôi đã hoàn thành việc cài đặt các gói quan trọng hoặc cần thiết Bây giờ, hãy xem việc thực hiện dưới đây:
Python3
https://webscraper.io/test-sites/e-commerce/static/computers/laptops?page=20 import https://webscraper.io/test-sites/e-commerce/static/computers/laptops?page=22 https://webscraper.io/test-sites/e-commerce/static/computers/laptops?page=23 https://webscraper.io/test-sites/e-commerce/static/computers/laptops?page=24 https://webscraper.io/test-sites/e-commerce/static/computers/laptops?page=25 https://webscraper.io/test-sites/e-commerce/static/computers/laptops?page=26 https://webscraper.io/test-sites/e-commerce/static/computers/laptops?page=27 https://webscraper.io/test-sites/e-commerce/static/computers/laptops?page=28 https://webscraper.io/test-sites/e-commerce/static/computers/laptops?page=29 pip install selenium0 pip install selenium1 pip install selenium2223 pip install selenium221 pip install selenium7 pip install selenium8 https://webscraper.io/test-sites/e-commerce/static/computers/laptops?page=24 pip install webdriver_manager0 pip install selenium7 pip install webdriver_manager2 pip install selenium7 pip install webdriver_manager4 https://webscraper.io/test-sites/e-commerce/static/computers/laptops?page=24 pip install webdriver_manager6 pip install webdriver_manager7 pip install webdriver_manager8 pip install selenium7 pip install xlsxwriter0 https://webscraper.io/test-sites/e-commerce/static/computers/laptops?page=24 pip install webdriver_manager6 pip install xlsxwriter3 pip install webdriver_manager8 pip install selenium7 pip install xlsxwriter6 https://webscraper.io/test-sites/e-commerce/static/computers/laptops?page=24 pip install webdriver_manager6 pip install xlsxwriter9 pip install webdriver_manager8 pip install selenium7 from 2https://webscraper.io/test-sites/e-commerce/static/computers/laptops?page=24 pip install webdriver_manager6 from 5pip install webdriver_manager8 pip install selenium7 https://webscraper.io/test-sites/e-commerce/static/computers/laptops?page=26 from 9https://webscraper.io/test-sites/e-commerce/static/computers/laptops?page=28 https://webscraper.io/test-sites/e-commerce/static/computers/laptops?page=29 pip install selenium0 selenium 3selenium 4
Output: Lưu trữ dữ liệu trong tệp Excel: Bây giờ, chúng tôi sẽ lưu trữ dữ liệu từ Element_List đến Excel File bằng gói XLSXWRITER. Vì vậy, trước tiên, chúng tôi phải cài đặt gói xlsxwriter này.element_list to Excel file using xlsxwriter package. So, First, we have to install this xlsxwriter package. pip install xlsxwriter Sau khi cài đặt, hoàn thành. Hãy cùng xem mã đơn giản mà qua đó chúng ta có thể chuyển đổi danh sách các phần tử thành tệp Excel.list of elements into an Excel file. Python3
pip install selenium7 import 4https://webscraper.io/test-sites/e-commerce/static/computers/laptops?page=24 import 6pip install selenium7 https://webscraper.io/test-sites/e-commerce/static/computers/laptops?page=26 import 9https://webscraper.io/test-sites/e-commerce/static/computers/laptops?page=28 webdriver 1webdriver 2
Đầu tiên, chúng tôi đang tạo một sổ làm việc có tên result.xlsx. Sau đó, chúng tôi sẽ coi danh sách sản phẩm duy nhất là một hàng duy nhất. Liệt kê danh sách là một hàng và dữ liệu của nó là các cột bên trong tệp excel đang bắt đầu dưới dạng hàng số 0 và cột số 0. & nbsp;result.xlsx. After that, We will consider the list ofa single product as a single row. Enumerate the list as a row and its data as columns inside the Excel file which is starting as a row number 0 and column number 0. Bây giờ, hãy để Lừa xem việc thực hiện của nó: Python3
https://webscraper.io/test-sites/e-commerce/static/computers/laptops?page=20 import https://webscraper.io/test-sites/e-commerce/static/computers/laptops?page=22 https://webscraper.io/test-sites/e-commerce/static/computers/laptops?page=23 https://webscraper.io/test-sites/e-commerce/static/computers/laptops?page=24 https://webscraper.io/test-sites/e-commerce/static/computers/laptops?page=25 https://webscraper.io/test-sites/e-commerce/static/computers/laptops?page=26 https://webscraper.io/test-sites/e-commerce/static/computers/laptops?page=27 https://webscraper.io/test-sites/e-commerce/static/computers/laptops?page=28 https://webscraper.io/test-sites/e-commerce/static/computers/laptops?page=29 pip install selenium0 pip install selenium1 pip install selenium2223 pip install selenium221 pip install selenium7 pip install selenium8 https://webscraper.io/test-sites/e-commerce/static/computers/laptops?page=24 pip install webdriver_manager0 pip install selenium7 pip install webdriver_manager2 pip install selenium7 pip install webdriver_manager4 https://webscraper.io/test-sites/e-commerce/static/computers/laptops?page=24 pip install webdriver_manager6 pip install webdriver_manager7 pip install webdriver_manager8 pip install selenium7 pip install xlsxwriter0 https://webscraper.io/test-sites/e-commerce/static/computers/laptops?page=24 pip install webdriver_manager6 pip install xlsxwriter3 pip install webdriver_manager8 pip install selenium7 pip install xlsxwriter6 https://webscraper.io/test-sites/e-commerce/static/computers/laptops?page=24 pip install webdriver_manager6 pip install xlsxwriter9 pip install webdriver_manager8 pip install selenium7 from 2https://webscraper.io/test-sites/e-commerce/static/computers/laptops?page=24 pip install webdriver_manager6 from 5pip install webdriver_manager8 pip install selenium7 https://webscraper.io/test-sites/e-commerce/static/computers/laptops?page=26 from 9https://webscraper.io/test-sites/e-commerce/static/computers/laptops?page=28 https://webscraper.io/test-sites/e-commerce/static/computers/laptops?page=29 pip install selenium0 selenium 3selenium 4
pip install selenium7 import 4https://webscraper.io/test-sites/e-commerce/static/computers/laptops?page=24 import 6pip install selenium7 https://webscraper.io/test-sites/e-commerce/static/computers/laptops?page=26 import 9https://webscraper.io/test-sites/e-commerce/static/computers/laptops?page=28 webdriver 1webdriver 2
Output: Đầu tiên, chúng tôi đang tạo một sổ làm việc có tên result.xlsx. Sau đó, chúng tôi sẽ coi danh sách sản phẩm duy nhất là một hàng duy nhất. Liệt kê danh sách là một hàng và dữ liệu của nó là các cột bên trong tệp excel đang bắt đầu dưới dạng hàng số 0 và cột số 0. & nbsp; Nhấn vào đây để tải xuống tệp đầu ra. Làm thế nào để bạn cạo dữ liệu từ nhiều trang web bằng Selenium Python?Xóa web bằng Selenium và Python.. Installation.. Bắt đầu nhanh. Chế độ không đầu Chrome. Thuộc tính trang WebDriver .. Định vị các yếu tố. Các phương pháp Find_element. Selenium Webelement. .... Chụp ảnh màn hình .. Chờ đợi một yếu tố có mặt .. Thực hiện JavaScript .. Sử dụng proxy với dây selen .. Chặn hình ảnh và JavaScript .. Làm cách nào để loại bỏ tất cả các trang từ một trang web trong Python?Cạo tất cả các trang con của một trang web trong Python.. Nhập các mô -đun cần thiết. Nhập yêu cầu. .... Viết một chức năng để lấy dữ liệu văn bản từ URL trang web .. Viết một chức năng để nhận tất cả các liên kết từ một trang và lưu trữ chúng trong danh sách. .... Viết một chức năng lặp trên tất cả các trang con..... Tạo vòng lặp .. Làm thế nào để bạn cào nhiều trang web trong Python?Cạo nhiều trang của một trang web bằng Python.. Chúng tôi sẽ nhập tất cả các thư viện cần thiết .. Thiết lập chuỗi URL của chúng tôi để tạo kết nối bằng thư viện yêu cầu .. Phân tích dữ liệu có sẵn từ trang đích bằng trình phân tích cú pháp của Thư viện BeautifulSoup .. Làm cách nào để xóa dữ liệu từ nhiều trang web?Q: Làm thế nào để cạo dữ liệu từ nhiều trang/url web ?.. Kéo một hành động vòng lặp vào quy trình làm việc .. Chọn danh sách của chế độ URL của URL .. Nhập/dán danh sách các URL bạn muốn cạo vào hộp văn bản .. Đừng quên nhấp vào OK và lưu nút .. |