您的位置:首页 > 编程语言 > Python开发

python写的command下运行的友情链接检测小程序

2009-11-21 12:06 369 查看
工作中需要做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("...........................")
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: