import suggests import time import dataset db = dataset.connect('mysql://choozmo:pAssw0rd@139.162.121.30:33306/marketing_cal?charset=utf8mb4') table=db['relations'] kw='買屋' s = suggests.suggests.get_suggests(kw, source='google') for sg in s['suggests']: table.insert({'src':kw,'dest':sg }) time.sleep(1) s2 = suggests.suggests.get_suggests(sg, source='google') for elmt in s2['suggests']: table.insert({'src':sg,'dest':elmt }) db.commit()