Hướng dẫn python wget progress bar - thanh tiến trình python wget

3

Mới! Lưu câu hỏi hoặc câu trả lời và sắp xếp nội dung yêu thích của bạn. Tìm hiểu thêm.
Learn more.

Tôi đang cố gắng tải xuống các tệp trong Python bằng mô -đun WGET. Tôi hiểu rằng nó được cho là có một số chế độ thanh tiến trình nhưng không thực sự hiển thị trong bảng điều khiển.

Tôi không thể tìm thấy bất kỳ tài liệu cho mô -đun này.

import wget from pathlib import Path print('Beginning download...') url = '//storage.googleapis.com/meirtvmp3/archive/hebrew/mp3/sherki/daattvunot/idx_69115.mp3' wget.download(url)

Các tập tin tải xuống nhưng không có thanh tiến trình hiển thị.

Mã nguồn cho mô -đun có một tham chiếu đến nó. Nhưng khi tôi thử nó trong mã Python của mình không thể tìm thấy một tham chiếu đến nó.

CHỈNH SỬA

Tôi đã kiểm tra kịch bản từ thiết bị đầu cuối và nó hoạt động như mong đợi. Tôi đoán đó là một lỗi Pycharm/VENV.

Hỏi ngày 26 tháng 9 năm 2019 lúc 22:00Sep 26, 2019 at 22:00

medic17medic17medic17

3653 Huy hiệu bạc14 Huy hiệu Đồng3 silver badges14 bronze badges

15

Điều này làm việc cho tôi,

#create this bar_progress method which is invoked automatically from wget def bar_progress(current, total, width=80): progress_message = "Downloading: %d%% [%d / %d] bytes" % (current / total * 100, current, total) # Don't use print() as it will print in new line every time. sys.stdout.write("\r" + progress_message) sys.stdout.flush() #Now use this like below, url = '//url_to_download' save_path = "/home/save.file" wget.download(url, save_path, bar=bar_progress)

Đã trả lời ngày 21 tháng 4 năm 2020 lúc 14:51Apr 21, 2020 at 14:51

Sumsuddin shojibsumsuddin shojibSumsuddin Shojib

3.3733 huy hiệu vàng24 Huy hiệu bạc43 Huy hiệu đồng3 gold badges24 silver badges43 bronze badges

2

Trong một bài đăng gần đây về việc tải xuống các tệp trong Python, chúng tôi đã học được cách sử dụng mô -đun #create this bar_progress method which is invoked automatically from wget def bar_progress(current, total, width=80): progress_message = "Downloading: %d%% [%d / %d] bytes" % (current / total * 100, current, total) # Don't use print() as it will print in new line every time. sys.stdout.write("\r" + progress_message) sys.stdout.flush() #Now use this like below, url = '//url_to_download' save_path = "/home/save.file" wget.download(url, save_path, bar=bar_progress) 0 để kiểm tra tài nguyên có thể tải xuống và hạn chế một số biện pháp để lấy các tệp từ xa. Để nâng cao kiến ​​thức của chúng tôi về chủ đề này, tôi sẽ giới thiệu cho bạn một phần giới thiệu khác để làm quen với mô -đun #create this bar_progress method which is invoked automatically from wget def bar_progress(current, total, width=80): progress_message = "Downloading: %d%% [%d / %d] bytes" % (current / total * 100, current, total) # Don't use print() as it will print in new line every time. sys.stdout.write("\r" + progress_message) sys.stdout.flush() #Now use this like below, url = '//url_to_download' save_path = "/home/save.file" wget.download(url, save_path, bar=bar_progress) 1, đó là việc thực hiện lệnh #create this bar_progress method which is invoked automatically from wget def bar_progress(current, total, width=80): progress_message = "Downloading: %d%% [%d / %d] bytes" % (current / total * 100, current, total) # Don't use print() as it will print in new line every time. sys.stdout.write("\r" + progress_message) sys.stdout.flush() #Now use this like below, url = '//url_to_download' save_path = "/home/save.file" wget.download(url, save_path, bar=bar_progress) 1 đi cùng với hệ điều hành. Bây giờ, hãy bắt đâù.

  • Lệnh WGET là gì?
    • Kêu gọi
    • Ví dụ
      • Ví dụ 1: Tải xuống phần mềm Poweriso mà không cung cấp bất kỳ tùy chọn nào
      • Ví dụ 2: Sử dụng lệnh wget để lưu tệp đã tải xuống dưới tên khác nhau
  • Giới thiệu ngắn về mô -đun WGET
  • Cách tải xuống các tệp với wget
    • Cách sử dụng
    • Sử dụng API
    • Tùy chỉnh thanh tiến trình
  • Sự kết luận
  • Người giới thiệu

Lệnh WGET là gì?

Kêu gọi

Kêu gọi

Ví dụ

wget [options]... [URL]

Ví dụ 1: Tải xuống phần mềm Poweriso mà không cung cấp bất kỳ tùy chọn nào

Ví dụ 2: Sử dụng lệnh wget để lưu tệp đã tải xuống dưới tên khác nhau

OPTIONS Option Syntax Since Wget uses GNU getopt to process command-line arguments, every option has a long form along with the short one. Long options are more convenient to remember, but take time to type. You may freely mix different option styles, or specify options after the command-line arguments. Thus you may write: wget -r --tries=10 //fly.srk.fer.hr/ -o log The space between the option accepting an argument and the argument may be omitted. Instead of -o log you can write -olog. You may put several options that do not require arguments together, like: wget -drc <URL> This is completely equivalent to: wget -d -r -c <URL> Since the options can be specified after the arguments, you may terminate them with --. So the following will try to download URL -x, reporting failure to log: wget -o log -- -x The options that accept comma-separated lists all respect the convention that specifying an empty list clears its value. This can be useful to clear the .wgetrc settings. For instance, if your .wgetrc sets "exclude_directories" to /cgi-bin, the following example will first reset it, and then set it to exclude /~nobody and /~somebody. You can also clear the lists in .wgetrc.

Ví dụ

Ví dụ 1: Tải xuống phần mềm Poweriso mà không cung cấp bất kỳ tùy chọn nào

Ví dụ 2: Sử dụng lệnh wget để lưu tệp đã tải xuống dưới tên khác nhau

wget //d32si1eewy6hfa.cloudfront.net/ov2so5=3ex040/PowerISO7-x64.exe

Giới thiệu ngắn về mô -đun WGET

Ví dụ 2: Sử dụng lệnh wget để lưu tệp đã tải xuống dưới tên khác nhau

Giới thiệu ngắn về mô -đun WGET

wget -O latest-hugo.zip //github.com/gohugoio/hugo/archive/master.zip

Cách tải xuống các tệp với wget

Cách sử dụng

Giới thiệu ngắn về mô -đun WGET

Cách tải xuống các tệp với wget

Cách sử dụng

Cách tải xuống các tệp với wget

Cách sử dụng

python -m wget [options] <URL>

options:

Sử dụng API

Sử dụng API

>>> import wget >>> url = '//www.futurecrew.com/skaven/song_files/mp3/razorback.mp3' >>> filename = wget.download(url) 100% [................................................] 3841532 / 3841532 >>> filename 'razorback.mp3'

Tùy chỉnh thanh tiến trình

>>> wget.download(url, bar=bar_thermometer)

Lệnh #create this bar_progress method which is invoked automatically from wget def bar_progress(current, total, width=80): progress_message = "Downloading: %d%% [%d / %d] bytes" % (current / total * 100, current, total) # Don't use print() as it will print in new line every time. sys.stdout.write("\r" + progress_message) sys.stdout.flush() #Now use this like below, url = '//url_to_download' save_path = "/home/save.file" wget.download(url, save_path, bar=bar_progress) 1 là một tiện ích không tương tác để tải xuống các tệp từ xa từ Internet được tích hợp sẵn với các hệ điều hành dựa trên UNIX. Nó hỗ trợ & NBSP;

Example:

Theo mặc định, WGET rất đơn giản để gọi. Cú pháp cơ bản là:

Wget sẽ chỉ đơn giản tải xuống tất cả các url & nbsp; được chỉ định trên dòng lệnh. & Nbsp; url & nbsp; là bộ định vị tài nguyên thống nhất, như được định nghĩa dưới đây.

Tùy chỉnh thanh tiến trình

Lệnh #create this bar_progress method which is invoked automatically from wget def bar_progress(current, total, width=80): progress_message = "Downloading: %d%% [%d / %d] bytes" % (current / total * 100, current, total) # Don't use print() as it will print in new line every time. sys.stdout.write("\r" + progress_message) sys.stdout.flush() #Now use this like below, url = '//url_to_download' save_path = "/home/save.file" wget.download(url, save_path, bar=bar_progress) 1 là một tiện ích không tương tác để tải xuống các tệp từ xa từ Internet được tích hợp sẵn với các hệ điều hành dựa trên UNIX. Nó hỗ trợ & NBSP;

def bar_custom(current, total, width=80): print("Downloading: %d%% [%d / %d] bytes" % (current / total * 100, current, total)) wget.download('//download.geonames.org/export/zip/US.zip', bar=bar_custom)

Sự kết luận

Trong bài đăng này, tôi vừa trình bày phương thức được sử dụng phổ biến nhất để tải xuống các tệp trong Python.Cá nhân, tôi thích sử dụng mô -đun #create this bar_progress method which is invoked automatically from wget def bar_progress(current, total, width=80): progress_message = "Downloading: %d%% [%d / %d] bytes" % (current / total * 100, current, total) # Don't use print() as it will print in new line every time. sys.stdout.write("\r" + progress_message) sys.stdout.flush() #Now use this like below, url = '//url_to_download' save_path = "/home/save.file" wget.download(url, save_path, bar=bar_progress) 0 để tải xuống các tệp do sự kết hợp giữa đơn giản và sức mạnh.Tuy nhiên, dự án của bạn có thể có các ràng buộc ngăn bạn sử dụng các thư viện của bên thứ 3, trong trường hợp đó tôi sẽ sử dụng mô -đun ____ 24 & nbsp; (cho Python 2) hoặc & nbsp;

Bạn thích thư viện nào và tại sao?Hãy cho chúng tôi biết trong các ý kiến!

Người giới thiệu

.

.

.

Chủ đề