If you have problems opening webpages, take a look at these troubleshooting techniques suggested by Apple.
https://support.apple.com/en-us/HT204098
Go to Safari menu (At the very top right side of your screen next to Apple icon), choose "Quit Safari"
press "Shift" button and while holding this button on your keyboard single click on the Safari icon on your Dock.
Open Safari - Preferences - Privacy - Remove All Website Data.
Open the Go menu with Option (Alt) key pressed - Library - locate Safari folder and move it to your desktop.
Apart from that, I'd recommend to use Malwarebytes Anti-Malware: http://www.adwaremedic.com/index.php
You can also remove the adware manually using the steps provided by Apple: https://support.apple.com/en-us/HT203987
Also, I believe it would be a good idea to install AdBlock.
Open Safari - Preferences - Search and set the default search engine to Google.