China allows for a 72-hour “transit without visa” that basically covers exactly this situation. It requires proof that you’re in transit (booked flights and arrangements that demonstrate you’ll be moving on).
Nationalities eligible for this include: Argentina, Austria, Australia, Belgium, Albania, Bosnia/Herzegovina, Brazil, Brunei, Bulgaria, Canada, Chile, Croatia, Cyprus, Czech Republic, Denmark, Estonia, Finland, France, Germany, Greece, Hungary, Iceland, Ireland, Italy, Japan, Latvia, Lithuania, Luxembourg, Macedonia, Malta, Mexico, Netherlands, New Zealand, Poland, Portugal, Qatar, Republic of Montenegro, Romania, Russia, Serbia, Singapore, Slovakia, Slovenia, South Korea, Spain, Sweden, Switzerland, United Arab Emirates, Ukraine, United Kingdom and United States.