2013-12-07 65 views

回答

1

你可以使用urllib.request stdlib module获取的网址:

#!/usr/bin/env python3 
from urllib.request import urlopen 

try: 
    with urlopen("http://apache.domain.com/get.php?id=1001") as response: 
      print("Has content" if response.read(1) else "Content Empty") 
except OSError as e: 
    print("error happened: {}".format(e)) 
+0

真棒。完美的作品。谢谢 – John

3

我建议使用Python Requests

import requests 
response = requests.get("http://apache.domain.com/get.php?id=1001") 
print response.text 

然后,您可以采取取决于什么response.text包含了必要的行动。

+1

'response.text'读取所有(可能无限制)的内容并尝试将其解码为Unicode。如果您只需要查明页面是否为空,那么这是不必要的,并且可能是有害的。 – jfs