#!/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
f の ff:
そうでない場合re.search("baidu",ff) ではなく、re.search("^s?",ff) および 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 "vbs" "jb51.net"