2013-12-07 66 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