As we know the light of Galadriel's Phial drove Shelob away. But that light was merely a fraction of fraction of the light of the Trees -- one of the Silmarils from far away in a small phial. Given this, how could possibly Ungoliant withstand the light of the trees at their brightest?
This isn't directly explained in Tolkien's writings, so we have to piece things together. That said, there are a couple of observations that make this somewhat more sensible than one might expect.
Shelob is less powerful than Ungoliant
Adamant suggests this in a comment on the question; one of the major themes of Tolkien's writing is that things in the distant past are more impressive and powerful than things in more recent times. Shelob belongs to a more recent age, while the Silmarils belong to a more ancient one, so they win; Ungoliant, meanwhile, is ancient beyond reckoning, while the Trees of Valinor are comparatively recent.
Ungoliant has her Unlight
In the published Silmarillion, we're told that Ungoliant goes forth with a black cloud of what Tolkien calls "Unlight", which seems to grow the more of the Light she consumes:
A cloak of darkness she wove about them when Melkor and Ungoliant set forth; an Unlight, in which things seemed to be no more, and which eyes could not pierce, for it was void.
It is told that even as Fëanor and Fingolfin stood before Manwë there came the mingling of the lights, when both Trees were shining, and the silent city of Valmar was filled with a radiance of silver and gold. And in that very hour Melkor and Ungoliant came hastening over the fields of Valinor, as the shadow of a black cloud upon the wind fleets over the sunlit earth; and they came before the green mound Ezellohar. Then the Unlight of Ungoliant rose up even to the roots of the Trees, and Melkor sprang upon the mound; and with his black spear he smote each Tree to its core, wounded them deep, and their sap poured forth as it were their blood, and was spilled upon the ground. But Ungoliant sucked it up, and going then from Tree to Tree she set her black beak to their wounds, till they were drained; and the poison of Death that was in her went into their tissues and withered them, root, branch, and leaf; and they died. And still she thirsted, and going to the Wells of Varda she drank them dry; but Ungoliant belched forth black vapours as she drank
The Silmarillion III Quenta Silmarillion Chapter 8: "Of the Darkening of Valinor"
It's not entirely clear how this Unlight reacts with the Light of the Trees; it seems like the Trees at least repel it, since it's described as going only to their roots, but it's possible that it affords Ungoliant some protection, which Shelob doesn't have.
It's also worth pointing out that, at first, she only drinks from the Light that spills on the ground; it isn't until she's already consumed some of the Light that she goes to the Trees themselves. Considering that consuming the Light of the Trees ultimately strengthens her to the point that she can pose a credible threat to Morgoth himself. I would suggest that it's also possible that consuming the Light strengthens her to the point that she can bear it, while the Trees themselves have simultaneously been weakened by Morgoth's attack.