用py写了一个获取手机所在地区的工具。哈哈,纯当练习之用。
#####phone.txt内容####
11位手机
11位手机
…
#######################
# coding:UTF-8 import urllib f = open("phone.txt") line_list = f.readlines() all_lines = "" address = "http://...?amount=10000&callname=getPhoneNumInfoExtCallback&mobile=" for lines in line_list: phone = "".join(lines.split()) try: html = urllib.urlopen(address + phone).read() all_lines += "%s\t%s\t%s\n" % (html[int(html.index("le:'")) + 4 : int(html.index("',province"))], html[int(html.index("sp:'")) + 4 : int(html.index("',stock"))], html[int(html.index("ce:'")) + 4 : int(html.index("',isp"))]) except Exception, e: print e.args pass o = open('phone-data.txt', 'a') o.writelines(all_lines) o.close() f.close()