python网络爬虫

class Clawer():
    headers = {
        'User-Agent':'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.1.6) Gecko/20091201 Firefox/3.5.6'
    }
    def __init__(self):
        socket.setdefaulttimeout(20)

    def openurl(self,url):
        req = urllib2.Request(url=url,headers = self.headers)
        response = urllib2.urlopen(req)
        the_page = response.read()
        return the_page

c = Clawer()
c.openurl('http://blog.csdn.net/ch_jinyi/article/details/7540187')

posted on 2015-03-09 21:00  长456风  阅读(102)  评论(0编辑  收藏  举报

导航