通用Python网络爬虫框架

#!/usr/bin/env python
# encoding:utf-8

import requests

def getContent(url):
    try:
        response = requests.get(url)
        response.raise_for_status()
        response.encoding = response.apparent_encoding
        return response.text
    except Exception, e:
        return str(e)

def main():
    url = "http://www.jianshu.com/"
    print getContent(url)

if __name__ == "__main__":
    main()

你可能感兴趣的:(通用Python网络爬虫框架)