____ _ __ __ ______ _____
/ __ __ _| | / /__ / /_ / ____/___ ____ __ __ /__ /
/ /_/ / / / / | /| / / _ / __ / / / __ / __ / / / / / /
/ ____/ /_/ /| |/ |/ / __/ /_/ / /___/ /_/ / /_/ / /_/ / / /
/_/ __, / |__/|__/___/_.___/____/____/ .___/__, / /_/
/____/ /_/ /____/
Created By : Raja Tomar License : Apache License 2.0 Email: [email protected]
Pywebcopy adalah alat gratis untuk menyalin situs web penuh atau parsial secara lokal ke hard-disk Anda untuk dilihat secara offline.
PyWebCopy akan memindai situs web yang ditentukan dan mengunduh kontennya ke hard-disk Anda. Tautan ke sumber daya seperti style-sheet, gambar, dan halaman lain di situs web akan secara otomatis dipetakan agar sesuai dengan jalur lokal. Menggunakan konfigurasi yang luas, Anda dapat menentukan bagian mana pun dari situs web yang akan disalin dan bagaimana caranya.
PyWebCopy akan memeriksa mark -up HTML dari situs web dan berupaya menemukan semua sumber daya yang ditautkan seperti halaman lain, gambar, video, unduhan file - apa saja dan segalanya. Ini akan mengunduh semua sumber daya tesis ini, dan terus mencari lebih banyak. Dengan cara ini, webcopy dapat "merangkak" seluruh situs web dan mengunduh semua yang dilihatnya dalam upaya untuk membuat faksimili yang masuk akal dari situs web sumber.
Pywebcopy tidak termasuk DOM virtual atau segala bentuk parsing JavaScript. Jika sebuah situs web memanfaatkan JavaScript untuk beroperasi, tidak mungkin PyWebCopy akan dapat membuat salinan yang benar jika tidak dapat menemukan semua situs web karena JavaScript yang digunakan untuk secara dinamis menghasilkan tautan.
PyWebCopy tidak mengunduh kode sumber mentah dari situs web, itu hanya dapat mengunduh apa yang dikembalikan server http. Meskipun akan melakukan yang terbaik untuk membuat salinan offline situs web, situs web yang digerakkan data canggih mungkin tidak berfungsi seperti yang diharapkan begitu mereka disalin.
pywebcopy tersedia di PYPI dan mudah diinstal menggunakan pip
$ pip install pywebcopy
Anda siap untuk pergi. Baca tutorial di bawah ini untuk memulai.
Anda harus selalu memeriksa apakah PyWebCopy terbaru berhasil diinstal.
>>> import pywebcopy
>>> pywebcopy.__version___
7.x.x
Versi Anda mungkin berbeda, sekarang Anda dapat melanjutkan tutorial.
Untuk menyimpan satu halaman apa pun, cukup ketik konsol Python
from pywebcopy import save_webpage
save_webpage (
url = "https://httpbin.org/" ,
project_folder = "E://savedpages//" ,
project_name = "my_site" ,
bypass_robots = True ,
debug = True ,
open_in_browser = True ,
delay = None ,
threaded = False ,
)Untuk menyimpan situs web lengkap (ini bisa membebani server target, jadi, hati -hati)
from pywebcopy import save_website
save_website (
url = "https://httpbin.org/" ,
project_folder = "E://savedpages//" ,
project_name = "my_site" ,
bypass_robots = True ,
debug = True ,
open_in_browser = True ,
delay = None ,
threaded = False ,
)Menjalankan tes sederhana dan tidak memerlukan perpustakaan eksternal. Cukup jalankan perintah ini dari Root Directory Paket PyWebCopy.
$ python -m pywebcopy --tests pywebcopy memiliki antarmuka baris perintah yang sangat mudah digunakan yang dapat membantu Anda melakukan tugas tanpa harus mengkhawatirkan dalam perjalanan jauh.
$ python -m pywebcopy --help Usage: pywebcopy [-p|--page|-s|--site|-t|--tests] [--url=URL [,--location=LOCATION [,--name=NAME [,--pop [,--bypass_robots [,--quite [,--delay=DELAY]]]]]]]
Python library to clone/archive pages or sites from the Internet.
Options:
--version show program's version number and exit
-h, --help show this help message and exit
--url=URL url of the entry point to be retrieved.
--location=LOCATION Location where files are to be stored.
-n NAME, --name=NAME Project name of this run.
-d DELAY, --delay=DELAY
Delay between consecutive requests to the server.
--bypass_robots Bypass the robots.txt restrictions.
--threaded Use threads for faster downloading.
-q, --quite Suppress the logging from this library.
--pop open the html page in default browser window after
finishing the task.
CLI Actions List:
Primary actions available through cli.
-p, --page Quickly saves a single page.
-s, --site Saves the complete site.
-t, --tests Runs tests for this library.
$ python -m pywebcopy run_tests Sebagian besar otentikasi waktu diperlukan untuk mengakses halaman tertentu. Sangat mudah untuk WebPage.session dengan pywebcopy karena menggunakan objek requests.Session . Dan seperti yang Anda ketahui ada ton tutorial tentang pengaturan otentikasi dengan requests.Session . Sesi.
Berikut adalah contoh untuk mengisi formulir
from pywebcopy . configs import get_config
config = get_config ( 'http://httpbin.org/' )
wp = config . create_page ()
wp . get ( config [ 'project_url' ])
form = wp . get_forms ()[ 0 ]
form . inputs [ 'email' ]. value = 'bar' # etc
form . inputs [ 'password' ]. value = 'baz' # etc
wp . submit_form ( form )
wp . get_links () Anda dapat membaca lebih lanjut di folder Github Repositories docs .