can you leave the airport if you have a long wait on a connecting flight

am thinking of flying to Beijing before going on to Phuket. One of the connecting times at Beijing airport is 9 hours. Do you have to stay in the airport for all of the time. or do get an opportunity to go out and explore?

TIA