工作中需要做SEO的工作.所以写了个友情链接检测的小程序.
 
python效率很高.程序中主要注意编码的问题.其他很是很简单的
 
# -*- coding: cp936 -*-
import urllib

def getcharset(url):
        html = urllib.urlopen(url)
        source = html.read()
        d = source.index('charset')
        d += 8
        if source[d] == 'u':
                source = source.decode('utf8')
                target = u'...................'
                add = source.find(target)
                if add == -1:
                        print "<<<警告>>>,对方网站没有链接"
                else:
                        print "友情链接正常"
        elif source[d] == 'g':
                source = source.decode('gbk')
                target = u'....................'
                add = source.find(target)
                if add == -1:
                        print "<<<警告>>>,对方网站没有链接"
                else:
                        print "友情链接正常"

if __name__ == '__main__':
        getcharset("...........................")