I always try to think that it wasn't meant to be. "What's for you won't pass by you".
I try to keep a positive mindset, and for each interview I prepare, read up on the company and the team, tailor my interview questions. An interview is a 2-way process, so I do go in with the attitude of do I want to work with you, and look for red flags.
Here is what happened to me just this year...
Interviewed in June at a great firm (I'm a lawyer), liked the team etc, interview went really well, but I didn't get the job. I genuinely just thought "well that really is their loss, as I am a good worker and a fab team player". Sounds arrogant, but it's took me many years to get to that stage, with a lot of self-doubt etc.
I interviewed a couple of weeks ago at another firm and have been offered the position, which is a promotion with a 10% payrise at a great firm with fantastic work. Now I wouldn't have entertained the interview, (I was approached and not actively looking) if I'd been offered the other job back in June. So I really believe that it's fate, which I know is a little ridiculous.
Hugs - it sucks, when you've been looking for a while, but you really will get there. You're getting to the interview stage, which is great. How are you during the interview? Do you do enough preparation and ask enough questions? Are you engaged and engaging. They are looking to see if you will fit in with the rest of the team. Sometimes it's really not even anything to do with you, other factors come into play.
Wishing you lots of luck.