requests抓取房多多

一,结果


requests抓取房多多_第1张图片
image.png

二,思路

三,代码


import requests
from bs4 import BeautifulSoup
import json
import threading

#url = 'http://shenzhen.fangdd.com/'
#url = 'http://esf.fangdd.com/shenzhen/'
class Fdd(object):
    def __init__(self):
        self.url='http://esf.fangdd.com/api/ioux/searchHouse'
        self.headers={
                'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36'
                ,'Cookie':'prev_pgn=%E5%88%97%E8%A1%A8%E9%A1%B5; _fa=FA1.0.1516252343056.4296232280; _ha=1516252345628.7531544026; mainwebwebsiteesffddToken=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ3ZWJjb2RldXVpZCI6ImFjNGU2ZmM2LTVhMzEtNDI5Ny1hNzZjLTgzZTJiMzFjZjYxOSIsImlhdCI6MTUxNjI1MjQxMywiZXhwIjoxNTE2ODU3MjEzfQ.iDV4nT9PS6iDWTtAOA6EJNNEKrsv7N-xXvEzlEcNm_c; webcodeuuid=ac4e6fc6-5a31-4297-a76c-83e2b31cf619; city_id=1337; _ga=GA1.2.1360255191.1516252344; _gid=GA1.2.1004278346.1516252344; webcomponentuuid=0668366b-944e-4581-900f-7e494cb772db'
                ,'Host':'esf.fangdd.com'
                     }
        self.data={
                    'city_id':'1337'
                    ,'from':'40'
                    ,'page':'1'
                    }

    def get_fdd(self):

        r = requests.post(self.url,headers = self.headers,data=self.data).text
        rdict = json.loads(r)
        rdata = rdict['data']
        records = rdata['records']
        #print(records)

        for a in records:
            aname = str('小区:')+a['cellName']+str(' 房型:')+a['flatName']+str(' 附言:')+a['houseRichName'] #房名

            b = a['flatName']   #房型
            c = a['housePrice'] #价钱W

            d = a['houseRichName']  #位置
            e = a['tags'] #附言
            f = a['area']   #平方

            #gg = a['blockName'] #具体城市
            h = a['createTime'] #最新时间
            j = a['unitPrice']  #一平
            aa = a['location']

            g = str(' 城市:')+aa['cityName']+str('  地址:')+aa['blockName']+aa['sectionName']+aname.replace(' ',',')
            print('价钱:{}万,单平:{}元,{}平米,{}'.format(c,j,f,g))
            items = ('价钱:{}万,单平:{}元,{}平米,{}'.format(c,j,f,g))

if __name__ == '__main__':
    l = Fdd()
    l.get_fdd()

            #print(str(c)+'W'+g)

            # print(aa['cityName'])
            # print(aa['blockName'])
            # print(aa['sectionName'])












你可能感兴趣的:(requests抓取房多多)