I, too, had the same problem before. Luckily, there are now several sites that offer free access to ebooks and articles of varying genre.
On top of my list is libgen.io. If the books you are looking for are academic then you will not be disappointed with the amount of books you can find in this site, not to mention how updated they are. You may also try browsing www.freebookspot.es, as they also have wide range of selection from engineering to programming to even fictional books. There is also this site: www.scribd.com where not only ebooks but also useful word, excel, pdf, and ppt files are uploaded.
If in case you still cannot find the book you want, you can always try searching google books and install the googlebooksdownloader program. This application will allow you to get copy of the available pages in pdf format.