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

检测百度关键字网站排名的python 程序

2013-01-26 10:23 519 查看
#!/usr/bin/env python

# -*- coding: utf-8 -*-

import sys

import urllib ,urllib2

import re

def baidu(w):

url= "http://www.baidu.com/s?"

values = {

"w":w.encode('gbk','ignore')

}

data = urllib.urlencode(values)

newurl = url + data

response = urllib2.urlopen(newurl)

the_page = response.read().decode('gbk','ignore')

return the_page

def ana(data,mysite):

o = re.compile("href=\"(.+?)\"")

f = o.findall(data)

line = 1

for ff in f:

if not re.search("baidu",ff) and not re.search("^s\?",ff) and re.search("^http:\/\/",ff):

if re.search(mysite,ff):

print "* " ,line ,ff

else:

print line ,ff

line += 1

if __name__ == "__main__":

mysite = sys.argv[2]

data = baidu(sys.argv[1].decode('utf-8'))

ana(data,mysite)

用法 python bd.py "关键字" 我的域名部分
:

python bd.py "123" "123.net"
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: