HOW DO I SET UP A PYTHON SCRIPT TO DOWNLOAD AN ENTIRE WEBSITE AND STORE IT IN ONE DIRECTORY?

Question by GIR:
How do I set up a Python script to download an entire website and store it in one directory?
I’m trying to set up a Python script to download all of the comics on xkcd.com and store them in “Desktop/xkcd” but I have no idea how to go about such a thing. Could I please have a tiny help?
——————————————
Answer by Colanth
Since you cannot locate all the files (they’re pngs and they have names, not just sequential numbers), you cannot just write code to download them all. You will have to write code to click the previous and next buttons to get all the comics, one at a time, then download each png file individually.
——————————————
Know better? Leave your own answer in the comments!









about 2 years ago
Just make the link go to the php file.
Click this link
about 2 years ago
For PHP code to work you need to have the webpage renamed with a .php extension or else the code will not execute.
about 2 years ago
It would help if you gave a few more details here. There are many different ways to execute a script. You’ll most likely have to use an IF statement. For example, say we have a page called example.php with a link on it that automatically changes the background color, using a PHP program:
Please type a color or HEX code in the following box to change background:I would suggest that you look up some PHP tutorials such as the excellent one found at http://www.w3schools.com/php/default.asp .
about 2 years ago
MKF is relatively correct, with the exception that that click on the link will completely refresh your page with the output of the Php script!
Remember that php runs and STAYS on the server. Its output IS an HTML page (with or without javascript included), so you can’t really “run a script” from the HTML sitting on the client’s side!
If you want to download a page, have a “link” to a php script, you have to use HTTPRequest to call that php script: that is made using the AJAX technique.
- You build your HTML page.
- In the page, you have an element with a name/id.
- A click on something will call a javascript function (already loaded on the client).
- That function will make an HTTPRequest to the server, to run the script/function
- The script will return an HTML “text” to update the Element…
about 2 years ago
It depends
1) If you want to activate it based upon a form submission, make the action attribute of
about 2 years ago
to open in same window ::
Open Same Window
to open in new window
Open New Window
Xicroz Xadanz