2011-06-14 8 views
164

me gustaría descargar una copia local de una página web y obtener toda la CSS, imágenes, JavaScript, etc.descargar una copia local de trabajo de una página web

En discusiones anteriores (por ejemplo here y here, tanto de los cuales son más de dos años de edad), dos sugerencias son generalmente presentadas: wget -p y httrack. Sin embargo, estas sugerencias fallan. Apreciaría mucho la ayuda con el uso de cualquiera de estas herramientas para realizar la tarea; las alternativas también son encantadoras.


Opción 1: wget -p

wget -p descargas con éxito todos los requisitos previos de la página web (CSS, imágenes, js). Sin embargo, cuando la carga de la copia local en un navegador web, la página no puede cargar los requisitos previos debido a que las rutas de acceso a esos requisitos previos no se han modificado a partir de la versión en la web.

Por ejemplo:

  • en HTML de la página, <link rel="stylesheet href="/stylesheets/foo.css" /> tendrá que ser corregido para que apunte a la nueva ruta relativa de foo.css
  • en el archivo CSS, background-image: url(/images/bar.png) necesitarán de manera similar a ajustar.

¿Hay alguna manera de modificar wget -p para que las rutas sean correctas?


Opción 2: httrack

httrack parece una gran herramienta para la duplicación de sitios web completos, pero no está claro para mí cómo usarlo para crear una copia local de una sola página. Hay un gran debate en los foros HTTrack sobre este tema (por ejemplo here) pero nadie parece tener una solución a prueba de balas.


Opción 3: ¿otra herramienta?

Algunas personas han sugerido herramientas de pago, pero simplemente no pueden creer que no es una solución libre por ahí.

Gracias tanto!

+14

Si la respuesta no funciona, trate de: 'wget -E -H -k -K -p http: // example.com' - sólo que esta trabajaban para yo. Crédito: http: // superusuario.com/a/136335/94039 –

+0

También hay software para hacer eso, [Teleport Pro] (http://www.tenmax.com/teleport/pro/home.htm). – pbies

+0

'wget --random-wait -r -p -e robots = off -U mozilla http: // www.example.com' – davidcondrey

Respuesta

207

wget es capaz de hacer lo que están pidiendo. Solo trata de lo siguiente:

wget -p -k http://www.example.com/ 

El -p le conseguirá todos los elementos necesarios para visualizar correctamente el sitio (CSS, imágenes, etc.). El -k va a cambiar todos los enlaces (para incluir los de CSS & imágenes) para que pueda ver la página en línea, ya que apareció en línea.

De los documentos Wget:

‘-k’ 
‘--convert-links’ 
After the download is complete, convert the links in the document to make them 
suitable for local viewing. This affects not only the visible hyperlinks, but 
any part of the document that links to external content, such as embedded images, 
links to style sheets, hyperlinks to non-html content, etc. 

Each link will be changed in one of the two ways: 

    The links to files that have been downloaded by Wget will be changed to refer 
    to the file they point to as a relative link. 

    Example: if the downloaded file /foo/doc.html links to /bar/img.gif, also 
    downloaded, then the link in doc.html will be modified to point to 
    ‘../bar/img.gif’. This kind of transformation works reliably for arbitrary 
    combinations of directories. 

    The links to files that have not been downloaded by Wget will be changed to 
    include host name and absolute path of the location they point to. 

    Example: if the downloaded file /foo/doc.html links to /bar/img.gif (or to 
    ../bar/img.gif), then the link in doc.html will be modified to point to 
    http://hostname/bar/img.gif. 

Because of this, local browsing works reliably: if a linked file was downloaded, 
the link will refer to its local name; if it was not downloaded, the link will 
refer to its full Internet address rather than presenting a broken link. The fact 
that the former links are converted to relative links ensures that you can move 
the downloaded hierarchy to another directory. 

Note that only at the end of the download can Wget know which links have been 
downloaded. Because of that, the work done by ‘-k’ will be performed at the end 
of all the downloads. 
+0

Gracias !! No tengo idea de cómo me perdí esa opción. – brahn

+2

Intenté esto, pero de alguna manera los enlaces internos como 'index.html # link-to-element-on-same-page' dejaron de funcionar. – rhand

+1

Todo el sitio: http://snipplr.com/view/23838/downloading-an-entire-web-site-with-wget/ –

Cuestiones relacionadas