Beispiel #1
0
def get_all(city, typeh):
    if city not in settings.beikecityDict:
        raise Exception('没有找到该城市')
    url = settings.beikecityDict[city]
    totalDict = {}
    if typeh not in ['二手房', '新房', '租房']:
        raise Exception('没有找到类型')
    totalDict['name'] = 'beike'
    totalDict['city'] = city
    totalDict['type'] = typeh
    totalDict['pages'] = 100
    totalList = []
    for i in range(1, 101):
        lists = get_page(page=i, base_url=url, typeh=typeh)
        for item in lists:
            totalList.append(item)
    totalDict['data'] = totalList
    jsonText = json.dumps(totalDict, ensure_ascii=False)
    if (typeh == '二手房'):
        jsonText = transform.trans_seconde_house(jsonText)
    elif (typeh == '新房'):
        jsonText = transform.trans_newHouse(jsonText)
    elif (typeh == '租房'):
        jsonText = transform.trans_rent_house(jsonText)
    return jsonText
Beispiel #2
0
def run(city,typeh,page):
    if city not in settings.fangCityDict:
        raise Exception('没有找到该城市')
    url=settings.fangCityDict[city]
    if page < 1 or page > 100:
        raise Exception('输入错误或越界,请重新输入!')
    totalDict = {}
    if typeh not in ['二手房','租房']:
        raise Exception('没有找到类型')
    totalDict['name']='fang'
    totalDict['city']=city
    totalDict['type'] = typeh
    totalDict['pages']=100
    totalDict['data']=get_page(page=page,base_url=url,typeh=typeh)
    jsonText=json.dumps(totalDict,ensure_ascii=False)
    if typeh=='二手房':
        jsonText=transform.trans_seconde_house(jsonText)
    else:
        jsonText=transform.trans_rent_house(jsonText)
    return jsonText
Beispiel #3
0
def run(city, typeh, page):
    if city not in settings.lianjiacityDict:
        raise Exception('没有找到该城市!')
    if typeh not in ['二手房', '新房', '租房']:
        raise Exception('没有找到相应类型')
    url = settings.lianjiacityDict[city]
    if page < 1 or page > 100:
        raise Exception('page小于1或越界')
    totalDict = {}
    totalDict['name'] = 'lianjia'
    totalDict['city'] = city
    totalDict['type'] = typeh
    totalDict['pages'] = 100
    totalDict['data'] = get_page(page=page, base_url=url, typeh=typeh)
    jsonText = json.dumps(totalDict, ensure_ascii=False)
    if (typeh == '二手房'):
        jsonText = transform.trans_seconde_house(jsonText)
    elif (typeh == '新房'):
        jsonText = transform.trans_newHouse(jsonText)
    elif (typeh == '租房'):
        jsonText = transform.trans_rent_house(jsonText)
    return jsonText
    return jsonText