Eh. I used to work for a polling company. Polling well is really, really hard. The maths behind it is relatively simple - you have something called the central limit theorem, which says that as your sample size increases, the sample mean approaches the population mean; or, as the number of people polled increases, how they say they'll vote approaches how the population says they'll vote. Get a sample size of ~1,000 and you have a margin of error of 3% with 95% confidence - that is, 95% of the time, the sample mean will be within 3 points of the population mean.
But then...
The first problem is if the sample isn't actually randomly selected. Imagine, for example, you don't conduct your polls in Spanish. You can't possibly contact any Spanish voters, so you have a bias in your sample and you'll end up with the voting figures for the population absent Spanish voters, which might be significantly off the real result.
The main way this actually reflects itself for pollsters, though, isn't language. For this election, it was differential response rates. Basically, when we call and say "do you mind if we ask a few questions?", you only get the answer "yes" about 7% of the time. 93% of the time they just say "no" and put the phone down. That means we're not selecting randomly any more - we end up oversampling the sort of person willing to answer the questions and undersampling the sort of person who isn't willing to do, usually the politically interested and the politically disinterested respectively. Unfortunately, these two groups don't vote the same way.
The second problem is dishonesty. There's two sorts of this problem. The first is: will this person vote at all? If I asked 5 people how they'd vote, and 4 said Blue and 1 said Red, but in the election, only Red turned up, my poll would have said 80/20 but the result would be 0/100. And the trouble is: there's absolutely no way to find out what the honest answer is. Some pollsters try asking people how likely they are to vote: for example, are you 7/10 likely to vote? 8/10? and then they exclude all people below a certain bar. Unfortunately, this doesn't work as well as you might expect, because different groups are differently accurate about their self-assessments. A millennial who says they are 7/10 likely to vote is actually much less likely than an older person who says they are 7/10 likely to vote. So the second way you can do it is by demographics - i.e., millennials normally vote at this rate, old people at this rate. But the trouble is that this leaves you massively susceptible to 'revolutionary' candidates, who can mobilize people in previously unforeseen ways.
The second part of this second problem is dishonesty about who you vote for. For example, you might want to vote for the racist candidate, but not want to admit it. So you'll say you're undecided, or you're voting for the other candidate, even though you're not. There's... really no way to do much about this for a pollster.
The third problem is undecideds themselves. If I poll 4 Red people and 3 Blue people and 2 undecideds, everyone thinks the pollsters are saying Red will win. But if all the undecideds swing behind Blue, they'll win 5-4 - and it looks like I was wrong. And because they're undecided, you can't really make any safe assumptions about them.
And finally the fourth problem is 'shock' events - last minute things that make people change their minds in between polls and polling day.
The trouble with this US election is that almost all of these happened at once! And there's really very little you can do about them. The more similar candidates are to previous elections, the better polling works. Obama vs. Romney and Obama vs. McCain? Easy to poll; Obama is obviously the same guy, McCain and Romney similar enough the same assumptions both work. But Trump vs. Clinton? Hard as heck to poll. And despite that, pollsters didn't do too bad. The standard error was about 2.3 percentage points on the national level. That's pretty close! The trouble is that was also the difference between President Trump and President Clinton.