Some thoughts ...
Most institutions that set homework have a policy that submitting answers you can't explain or copying without attribution is grounds for failing the course: either way you'll be no better placed when exams come round. Just copying code or answers to plug in to, for example, Project Euler, seems only to short-change the person who does it. We might view it differently if someone takes a code snippet we wrote, uses it in a project that gets into litigation over patents or copyright or fails in other ways where lawyers get involved.
For anything other than a trivial question there is skill in choosing good search terms and selecting a good answer from the ones offered. Defining 'good' is an interesting exercise: finding a code snippet to copy seems no better than having the snippet on SO. My 'good' would be somewhere that helps equip a person to deal with this class of question: ideally it gives a pointer to the tools and some insight but then sets the very question the questioner raised but without giving the solution :-)
Items found from a search are (likely) to be accessible to the questioner (unless the searches include material that is not available to everyone) whereas print books may not be accessible to a questioner or other readers of the question and its answers. In the long term, though, the book-style approach is likely to be better for the development of the questioner than learning how to cut and paste. The practice of giving references to materials that are not legal to download should be deprecated (even though establishing what is legal in every jurisdiction is not usually possible)
Internet links tend to decay over time. Is it better for SO, for example, to actually include the material (with attribution where appropriate) or refer to it elsewhere. I don't think we undertake to keep our answers up to date as links and technology change
Where a code sample is requested perhaps it should be enough to indicate how to approach the problem, at most giving some pseudocode -- I might go further and suggest code samples should contain (deliberate) errors or omissions or be given in obscure languages (Algol-68 or Coral-66, anyone?) but I suspect an avalanche of downvotes would ensue