Looking at folklore, spiders are not
always seen as evil. I cannot think of any prominent British folktales which feature spiders, not to the same extent that Anansi is known. There is the tale of Robert Bruce; hiding as a fugitive in a cave, so the familiar tale goes, he watched a spider try to weave her web over and over again, which inspired him not to give up. This is a story where the spider is an inspiration. There is a particular maypole dance known as the 'spider web', which involves people holding alternately coloured ribbons dancing in and then out of one another, creating a spider web pattern. And I remember the spider being one of the many things that the old woman swallowed after swallowing the fly.
Yet folktales from the Americas and Africa have trickster or evil spider characters. Perhaps this is due to other areas of the world having dangerous spiders, whereas in the UK our spiders are all totally harmless. We don't have Hunstman spiders for one thing, who will actually come over and bite you should they feel threatened; British spiders merely kindly offer their services by eating our flies and nits.
Even so, a lot of children seem to have a fear of spiders, which I think might stem from the fact that their webs get stuck all over you when you walk or run into them, which isn't nice (though much nastier for the poor spider). So Tolkien might have been playing up on some people's general fear of spiders, but I don't think he was making use of British folklore in creating giant, malevolent spiders. As someone who happens to find spiders fascinating creatures and who has no need to fear them, the fact that Shelob was a giant spider did not scare me, it was more the knowledge that she was a predatory creature made large which made me fear for Frodo and Sam.
I find the idea that Ungoliant sucked the Light from the Two Trees interesting as spiders do have a habit of liquifying their prey and sucking their food up. They are also a predatory creature, and they tend to live in darkened places; there is also a misconception that all female spiders kill and eat the males. For most of his giant spiders, I think Tolkien was simply using a creature associated with darkness and with predatory behaviour to conjour up a strong concept of fear. But as regards Ungoliant, Tolkien created something fascinating, as she is a creature which seems to be the antithesis of Light and creation, an arachnid black hole which devours light, so the idea of her being a personification of 'evil' is interesting. or perhaps rather than her being 'evil', maybe she is there as a necessary opposite to creation? Who created her? Is she on a 'par' with Eru?