随笔分类 - Python
摘要:python有一个python模块--hash_ring,即python中的一致性hash,使用起来也挺简单。可以参考下官方例子:https://pypi.python.org/pypi/hash_ring/ 1 Basic example of usage (for managing memcached instances): 2 3 memcache_servers = ['192.168.0.246:11212', 4 '192.168.0.247:11212', 5 '192.168.0.249:1121...
阅读全文
摘要:1 #baidu_hotword.py 2 #get baidu hotword in news.baidu.com 3 import urllib2 4 import os 5 import re 6 7 def getHtml(url): 8 page = urllib2.urlopen(url) 9 html = page.read()10 page.close()11 return html12 13 def getHotWord(html):14 reg = ''15 hotwords = re.compile(reg).finda...
阅读全文
摘要:1 #!/bin/python 2 # download_pic.py 3 # download picture 4 import os 5 import sys 6 from urllib.request import urlopen 7 8 url = sys.argv[1] 9 page = urlopen(url)10 #需要指定编码格式11 html = str(page.read(),encoding='utf8')12 page.close()13 14 #create directory15 if os.path.exists("./picture&q
阅读全文
浙公网安备 33010602011771号