Both dynasties experienced major catasthrophies.
Wang Mang usurped the throne, marking the end of the Western Han, reigned for 14 years, and was toppled. The Han dynasty was revived and lasted for almost 200 years after that, known as Eastern Han dynasty.
The Tang dynasty also got interrupted briefly by Empress Wu ZeTian who was the sole Zhou monarch for 15 years before power was return to her sons who restored the Tang Dynasty. Compared to the rebellion of An LuShan half a century later, it was a minor hiccup.
The real crisis of the Tang was the An LuShan's rebellion in AD 756 broke the power of the Tang dynasty. Though the dynasty lasted for another 150 years until AD 907, the dynasty did not have the kind of post-crisis recovery experienced by the Eastern Han dynasty.
Why the different fates?
In comparison to the Han when no Liu clan was emperor during the rebellion of Wang Mang, the Tang emperors continued to rule despite being forced from the traditional capitals of ChangAn and LuoYang. Much of the country remained loyal whereas the Liu clan of the Han dynasty had to start practically from scratch.
My personal assessment is that the answer could be found in the different social structures and makeup between the Han dynasty and Tang dynasty.
During the Han dynasty, power was distributed to landed hereditary aristocrats and gentries whose support was essential. With their background, these factions tend to be big on traditions, conservatives, and orthodoxy. The mainstay of their power were the farmlands, not urban cities.
In contrast, the power during the Tang dynasty was distributed to military governors who ruled from cities. Many came from humbler background as nobilities in the Tang had been shunning military service. The military governors had little respect for orthodoxy and traditions, many were unlearned and came to their positions through a career of violence.
Another factor was the presence of numerous non ethnic-Hans in the Tang, and the Tang's reliance on them for the military. When these tribes found the Tang no longer worthy of respect, they turned their skills against the empire for their own benefits.
I also considered significant that the primary restorer of the Han dynasty, Liu Xiu, rose through the ranks and personally led in combat before finally emerging victorious and establishing himself.
In contrast, Li Heng, who succeeded Emperor XuanZong, was known more for his poetry and had relied on loyal generals to fight his battles. Thus, his influence over the military was limited. Worse, he died before the rebellion was actually put down and the work of consolidation was left to his successor Li Yü (李豫) whose posthumous name was DaiZong. These rulers lacked personal prestige compared to Liu Xiu who was able to implement some reforms and strengthen his dynasty.
I would like to hear your opinions on these.