Make a screenshot and then find the most common color.
Is the most common color the same as the background?
You can visit a couple of websites and see if it is true. I guess for all practical purposes it is. Also this method can handle cases where an image is used as a background. And even for difficult cases like these it's better and much more simple than trying to deduce color from relations of nested blocks. Although it may give incorrect results for gradients, pattern backgrounds, and rich color variations.
How to automate screenshots?
You can use PhantomJS to capture the screenshot and then save it as a png file. This page should explain the details. Don't forget to lower viewport resolution to reduce amount of work.
How to find the most common color?
You can do it using NodeJS, Python, PHP, or any language that have appropriate tools. Just traverse the pixels, store color frequencies in a hash table and then find the key associated with the maximum value. In pseudocode:
table = new HashTable()
# Count the colors
for pixel in pixels:
if pixel.color not in table.keys:
table[pixel.color] = 0
table[pixel.color]++
# Find the color associated with the max count
result = table[table.keys[0]]
for color in table.keys:
if table[color] > table[result]:
result = color
print(result)
You could break the image into 10x10 blocks and pick one pixel from each to reduce the amount of computation but low resolution did the same job already, even better: there are also less IO.
How to put these parts together?
PhantomJS has NodeJS API so you can parse pages and find background colors in a single script. For other languages you can call PhantomJS command as an external process and wait until it finishes. Related docs for PHP and Python. Or just Bash, it should be even simpler if you can do Bash scripting.