If you want to visit Salem, then Quincy is about as far away as you can get.
Assuming you can't get Boston lodging (and you really really should try to, if more than half your touring is going to be in the city), then for Salem you should look for hotels in Peabody, Danvers, or Swampscott, as these are towns that are more likely to have Budget rooms for rent.