TL;DR
There are many ways of getting new weapons. : the most effective is trading with other players, jump to "Trading" if you want to save time.
Some very potent class weapons one can acquire by getting 5, 11, and 17, or 10, 16 and 22 class-related achievements, the number depends on the class, each milestone giving a class weapon. The weapons will be usable in crafting, but not tradable.
Without some of those weapons, playing Team Fortress 2 can be hard and unpleasurable, but you will get them inevitably if you just play the class normally.
While playing the game, every 30 to 70 minutes (random, average 50 minutes) you are guaranteed to find one item, usually a weapon. You have to click to accept the item before you can get a new one, so idling for a long time hardly helps, and no more than 10 hours per week per account count (average maximum of 12 weapons per week).
This is a steady way of getting new weapons, but you will find a lot of duplicates, and it really, really takes time.
Anyway, players accumulated a lot of random drops since they had been implemented in the Sniper vs. Spy Update back on May 21 in 2009, and it makes most ways of obtaining weapons besides trading no longer worth it. Again, read below.
For a new player, Mann vs. Machine mode is a good way to polish some skills, and you also get random drops as you do in a normal game. You may play on community on official servers — in the latter case, you have to pay money for each game you complete, having a Tour of Duty Ticket in your inventory. When you win a mission, you are guaranteed to get one random item, and one ticket will be consumed. A ticket costs ~$1. Each player may also present a Squad Surplus Voucher, which costs ~$2 and gives an additional random drop to each party member. If you are playing in a party of 6 friends (which is more fun than playing with random guys IMO), and each of you presents a Squad Surplus Voucher, then each of you gets 7 random drops for $3, or each item per $0.43. That can be fast, but not really an effective way of investing money in TF2.
Keep in mind, though, that you have a chance to get unusual items that are worth more than normal weapons, so it doesn’t mean that you shouldn’t play MvM to grind items.
With many attempts and trading, you might actually win more than you invest, but I didn't do the math, so currently I advise against this method.
To open a crate, you need to buy a Key, which costs $2.50. You can get some pretty amazing stuff from a crate, but it will take a long time and a lot of keys and crates to get the weapons you need. Don’t do it unless you are willing to invest some keys and then trade things that you get. Actually, buying keys to open crates is akin to gambling.
Plus, you will likely lose the competition to scammers that buy keys using stolen credit cards for money laundering...
Buying weapons directly from the Mann Co. Store
Yes, you can buy them straight away: if you read an article about any weapon in the game, you will notice that there’s a price for most of them. But that’s very, very ineffective money-wise. Don’t do that -- I was silly enough to do it multiple times in the past, and I could get a lot more for that money.
Instead of buying a weapon, you can always choose a test run and get one single weapon for 7 days. The item will be non-craftable and non-tradable, and you can only have one item for a test run at a time. When those 7 days end, the item fades, and you may select a new one for a test run, probably even the same item. However, you cannot select another weapon until the end of your current test run.
This is a good way of actually trying something out and/or compensating for not having an item. It was even better back in the day when a test run length was 2 days...
By salvaging duplicate weapons, you may obtain new ones. However, that’s not the most effective way of getting rid of duplicates, read below about trading. The point is that the costs of crafting most weapons are higher than what they are actually worth. Items that are worth crafting exist, but they are not standard weapons, they are mostly cosmetics.
The cost of crafting a new weapon is up to 37 standard weps, and in most cases, it’s around 7-13. Trading is much more effective.
You may exchange different items with other players.
Ask a fellow veteran player for help
If you have a friend who plays TF2 for long, they most likely have a lot of duplicate items in their inventory that aren’t really needed. You may ask your buddy to give you some for free.
Exchange 1:1 with your friends
If you have friends who play TF2 and don't have all the weapons yet, you can exchange duplicate or otherwise unneeded items. You may expect a 1:1 ratio, and it’s good.
Use a trading website to trade weapons 2:1 or one scrap metal per weapon
By smelting 2 class weapons, you may get 1 scrap metal for further use in crafting.
If you go to a trading website, you will see plenty of offers to trade two of your craftable weapons or 1 piece of scrap metal for any of the trader’s weapons. Your benefit is getting the desired weapon, trader’s benefit is getting more scrap metal for crafting hats.
3 pieces of scrap metal form 1 piece of reclaimed metal, and 3 units of reclaimed metal can be turned into 1 piece of refined metal.
You might find more information about trading and finding trade partners in a related question "How do I determine what my TF2 items are worth?", particularly in the accepted answer by @badp. Keep in mind, though, that prices have changed significantly since then!
A key, if you choose to sell it, costs around 50-55 pieces of refined metal (as of 8.01.2020), which can be turned into 50*9=350 pieces of scrap metal, each traded for one normal weapon. Again, prices could have changed by the moment you are reading this! Don't forget to recheck!
This is the most effective way to inject money in TF2 economy to get weapons.
My rough calculations using the MANN CO. CATALOG have shown that there are about 170 weapons in this game, barring those that are just normal weapons with some cosmetic quality added. It means that, for just one key, you can get every single weapon feature in this game besides cosmetics. Moreover, some of those ~170 weps are useless crap, some are reskins of others, so you will actually have a lot of metal left for buying cosmetics and probably sharing some weapons with your friends. You can even arm a bunch of full MvM squads this way!
I recommend you sell the key for refined metal, and then trade this metal for weapons, as the expected seller is unlikely to have a duplicate of every single weapon in the game just for you, plus you will need a lot of change anyway. :)
Buying weapons this way costs less than one cent per wep -- compare this price to buying each weapon for $1-2 from the Store or getting them for ~$0.43 to $1 from MvM.
Remember that trading only becomes available when you make at least one purchase in the Mann Co. Store, so I strongly suggest the key as that purchase. It will also upgrade your backpack, allowing you to store all those weapons you want to trade for.
Trade Holds: A very important note on trading
- If you and your trading partner were Steam friends for the last year, or you both have your Steam Guard Mobile Authenticator enabled, trading happens instantly. That's fast, isn't it?
- If you are friends, but for less than a year, and Steam Guard Mobile Authenticator is not on for any of you two, trades are put on hold for 3 days. It means that you will only get your items after the time passes.
- If you are not friends, trades are put on hold for whole 15 days! That's a lot of time.
Keep the holds in mind when trading. To avoid frustration from having to wait, enable Steam Guard Mobile Authenticator or at least friend each other.
Steam Guard Mobile Authenticator also does a good job protecting your account as a bonus. :)
Good luck!