web_utils.py 583 B

1234567891011121314151617181920212223242526
  1. # coding=utf-8
  2. """ 网络工具类 """
  3. import urllib2
  4. class WebUtils(object):
  5. """ 网络工具类 """
  6. @staticmethod
  7. def get(url_str):
  8. """ get 方法获取网络请求返回
  9. :param url_str: string
  10. :return: string 页面返回
  11. """
  12. request = urllib2.Request(url_str)
  13. response = urllib2.urlopen(request)
  14. if response.getcode() != 200:
  15. print response.getcode()
  16. return None
  17. return response.read()
  18. if __name__ == '__main__':
  19. url = "http://www.baidu.com"
  20. print WebUtils.get(url)