获取随机地址信息

in Like with 0 comment

最近测试个东西需要有大量的随机地址信息,网上找到一个api可以生成地址信息,所以用python写了个小程序,通过循环访问api获取数据后打印出来,由于不是码农,所以只求能用,代码质量请忽略。

# coding=utf-8

import urllib2
import json

while True:
    
    try:
        html = urllib2.urlopen(r'http://api.sinchang.me/random/user',timeout=1)
        hjson = json.loads(html.read())
        print hjson['items']['mobile'],
        print ",",
        print hjson['items']['name'].encode('utf-8').strip(),
        print ",",
        print hjson['items']['address'].encode('utf-8').strip()
#        break
    except Exception as e:
        print "Connect Timeout"
Comments are closed.