I get where you’re coming from. It’s hard to be sure from a relatively brief post, but I think my own problems overlap with yours. Apologies if these suggestions are obvious and/or useless – I’m not sure exactly what you’re looking for or what you’ve already tried.
If the comments are attached to content that you want to continue to read/watch, I second alm’s suggestion of a technological solution. For desktop Firefox, I use:
If you’d like to block some sites entirely, https://addons.mozilla.org/en-US/firefox/addon/leechblock-ng/ can do that. It’s fairly configurable, so you can also e.g. prevent yourself from accessing the comment section on a particular subreddit, without blocking that subreddit entirely; block a site at specified times of day, and/or days of the week; and allow yourself access to a site only for a limited amount of time per hour or per day. Like basically all such tools though, you’re not going to find it very hard to work around when the itch strikes, so it’s not going to be a complete solution. I think it can still be helpful, though.
Another strategy can be to find lesser evils, and set yourself realistic goals. For example, ideally you might like to spend that time reading quality literature or technical books instead. (Or writing your thesis, or doing your work, or making art, or whatever.) But when you’re in the kind of headspace where compulsive internet browsing is attractive, you might not have the mental energy to do that. Better to have a stack of [comic books/trashy fiction/addictive but harmless videogames/whatever else floats your boat] that you actually turn to, than high-minded alternatives that you don’t.
Excercise and music can also be great distractions. I’m terrible at everything to do with music, but memorising a fun-to-play song or two on the guitar, and leaving it next to the computer, really pays off. Excercise has all the benefits I’m sure you’re aware of, but even just doing a few pushups (or whatever) can serve as a nice brief distraction that leaves you feeling better about yourself rather than worse.