I’ve found that, like anything else, you can train yourself out of this kind of behavior simply by being conscious of it.
If you’re reading something on the web, pull the tab out into its own browser window and maximize it. If your OS of choice has a “silence notifications” option, use that. When you realize that you’ve gotten sidetracked just remind yourself that that’s not good and return to what you were doing.
Essentially this is a lite version of some mindfulness therapies. Over time actively centering yourself back in the moment will help your concentration just like it helps with anxiety.
While it doesn’t really help you, I thought I’d also relate a bit of an anecdote. For years and years I had a list of some of the “classics” that I felt like I should read because they were apparently so monumental we have to force every high school kid in the US to read them. For years I tried and made no progress - I could sit down with a fiction novel and be lost for hours, so it wasn’t my concentration, but any time I picked up something by (for example) Dickens I would spend three minutes actually reading and then my mind would wander. At some point I would notice that I’d been reading the same paragraph over and over and give up, disappointed in myself again.
Eventually I just realized that I simply hate Dickens and no amount of effort was going to make me start liking him. I had to admit that I was just never going to get that feeling of awe that I felt like I should have for any of his works and gave up and moved on to books I actually liked.
It won’t work if it’s something for work, but perhaps you’ve been focusing on things you feel like you should learn, but don’t really want to learn.