Anthony Weiner had the look of a haunted man.

“I appreciate you doing your job,” he told a small pack of reporters, through clenched jaws, Saturday afternoon as he left the Union Square apartment building he once shared with his wife, Huma Abedin, and only child, Jordan, 5.

“I don’t have anything to say,” he said.

His sides were heaving, and he looked like he was holding back tears as he stood on Union Square East.

“Thank you,” he coughed before bolting into a yellow cab.

Just one day ago, the 52-year-old former New York congressman and mayoral candidate pleaded guilty to sexting with a 15-year-old girl in North Carolina.

The facts of the case were grotesque. Weiner had engaged in sick “rape” fantasies with the girl, and urged her to dress up in plaid schoolgirl skirts. On Friday as he admitted his guilt and embarrassment to the judge, he cried.

Soon after leaving federal court — with prosecutors’ threat of a two-year prison sentence still ringing in his ears — he learned that his wife had just filed for divorce.

Now, with the threat of prison, a protracted custody battle and a quite likely toxic bachelorhood looming, Weiner’s life is getting ever smaller.

It wasn’t always this way.

Even in the years after his very first sexting scandal — one year into his marriage, in 2011, when he accidentally publicly tweeted out an underwear selfie instead of sending it to a woman who is not his wife — Weiner had seemed self-assured, cordial, connected.

His series of sexting scandals cost him his congressional seat, his mayoral bid, his dignity.

Still, through it all, he enjoyed jogging through his neighborhood, stopping for coffee-by-the-box at Starbucks, and playing with his son in the pool at the huge, 600-unit condo he called home.

“I used to see him in the pool with his kid,” one fellow resident at 1 Irving Place told The Post.

“He used to come to rooftop parties and smile, and be happy,” the neighbor said.

“He seemed like a good dad, I’ll be honest,” he said. “I saw him with his kid a lot, taking his kid to day care, playing with his kid in the pool.”

But this latest sexting scandal was different from the three that came before. After this last one, the sunglasses went on, the visits to the pool with the boy ended.

On Saturday, as Weiner scrambled away from reporters alone and near tears, Abedin was captured by paparazzi looking calm and lovely, leading by the hand their young son, who was dressed as if for a Little League game.

As he stepped off the sidewalk to better find an available cab, his camouflage-patterned baseball hat pulled down over his eyes, Weiner made a telling gesture.

He lowered the hand he was hailing with — his right. And with it, he fiddled with his wedding band, as if to check that it was still there.

“It took four embarrassments,” noted the neighbor, “before it really hit home that he f—ed up.”

The news that Weiner’s disturbing online exchanges with an underage girl may also have unwittingly helped swing the 2016 election to Donald Trump certainly didn’t help his marriage.

The investigation into his sexting with the 15-year-old led the feds to probe the laptop he shared with Abedin, a close aide to presidential candidate Hillary Clinton.

While no new classified State Department documents would ultimately be found, then-FBI Director James Comey announced days before the election that he was reopening the Clinton ­email investigation, an ­announcement widely thought to have contributed to her loss.

Now Weiner is a virtual hermit, scorned, derided, broke and alone, but for his mother and father in Brooklyn and his Manhattan restaurateur brother.

“He doesn’t seem to like to look people in the eye,” said Weiner’s neighbor.

“He obviously knows we know who he is,” said the resident, who asked that his name not be revealed.

‘I don’t think he’s going to be able to handle this. It’s one thing to be a political disgrace. It’s another thing to go to jail for two years.’ - Friend of Anthony Weiner

“He’s self-conscious . . . He just sort of walks away quickly,” said the source, who has heard rumors that Abedin and Weiner are moving out soon.

Weiner has stopped showing up at his local Starbucks.

“I haven’t seen him for a while,” said employee Jatwaun Parrish, 29, on Saturday.

“Like, six months. He would come in quite often. He would always order a ‘traveler,’” said Parrish, referring to the outlet’s 96-ounce coffee boxes. “He would come in around 8 a.m.”

Onetime pals say he has been avoiding them.

“He did it to himself,” a politician who has been friends with Weiner told The Post on Saturday.

“I don’t think he’s going to be able to handle this,” the friend added. “It’s one thing to be a political disgrace. It’s another thing to go to jail for two years.

“Huma was his meal ticket and I heard she completely cut him off. And Hillary pressed her hard to file for divorce.

“You cop to jail for whatever he did, and your wife files for divorce on the same day — that can’t be good,” the friend said.

“The problem Anthony has is that he didn’t have any real friends. He had political associates and people whom he paid to work for him.”

Weiner’s world will become still smaller once he completes his sentence, which prosecutors are recommending be set at 21 to 27 months.“They are going to keep him on a super-tight leash,” said defense lawyer Israel Fried.

Probation could limit his proximity to schools, whether he can teach or attend college classes, even whether he can drive a school bus.

“His internet will be controlled or limited,” said Fried, who specializes in representing sex offenders.

“At home they are probably going to monitor his access — if he’s given access at all,” he said.

“They’ll make routine, unannounced visits, and they will check his computer. If he visits certain [web]sites, he could be hauled back in.

“Probation will monitor every single aspect of his life.”

The state sex-offender registry will place more constraints on his life — and will continue to do so for the next 20 years or more.

Sometime after his Sept. 8 sentencing, Weiner will attend a hearing, in front of his federal sentencing judge, to determine at what sex-offender level the state of New York will monitor him over the course of those two ­decades.

The judge, by law, must consider how likely Weiner is to commit another crime, and how dangerous he may be to public safety overall.

Among the factors considered at these hearings: Was force used? Were there numerous victims? How old and vulnerable were the victims? Has he done it before? Might he do it again?

Fried thinks that, again given his notoriety, compulsiveness and heavy sentence, Weiner could well be judged a Level 2 (moderate-risk) or Level 3 (high-risk) offender — and the judge could keep him on the registry for life.

“New York is not very easy­going on these types of crimes, so it’s very possible he could land up there for life,” Fried said.

But regardless of how dangerous Weiner is determined to be, anytime he changes his address, he must inform the registry.

Local cops will then be told he is in their jurisdiction.

And those local cops could then inform the local school district, which has the discretion to inform all the families in the district, that Weiner is among them.

The school districts could then post pamphlets with Weiner’s name on them, or send out the alarm on email lists.

And since his 15-year-old victim was under the age of 18, Weiner could be banned from the grounds of any elementary, middle or high school, at the district’s discretion.

One exception would be his own son’s school.

Weiner would be able to visit there for a limited purpose — such as a parent-teacher conference, or sports game or contest — if he gets written permission from the judge or the school superintendent.

His divorce judge, though, would get the final veto. Any contact with the boy must be in compliance with whatever constraints are set in divorce court.

In setting Weiner’s access to his child, both the sentencing and divorce judges should keep in mind that Weiner is “an internet troll,” Fried said — not someone who ever had physical contact with a minor.

“To now limit his access to his own child, me as a defense attorney, I would say that is very invasive,” Fried said.

Additional reporting by Kaja Whitehouse, Nick Fugallo and Laura Italiano