Essentially what browsers do is just query Google's huge database of known malware sites for the URL/domain in question.
How Google builds up that database is a different story. They probably work together with various researchers and antivirus products to detect already known threats. Apart from that, they probably have some automatic detection of "suspicious" URLs or document contents (Flash, PDF, Java or browser exploit triggers, shellcode, ROP chains, heap spray scripts, ...). After all, they already have to look at all the contents for indexing, so they can easily perform relatively complex analysis. They also know of URLs pointed to by spam and phishing mails through their Mail service. What they probably don't do is manual malware analysis using sandboxing and such, this is the job of security/antivirus companies.
So all in all, this is quite a complex task. And no, there is no single Python script available that does that job (although if you're really interested in this, you'll find that there are actually a lot of small helper scripts and also more complex frameworks written in dynamic languages like Ruby or Python). Some projects you could look at to get started (and that are actually general enough to be very useful for other tasks as well):