【发布时间】:2019-05-28 12:57:18
【问题描述】:
我正在尝试通过此链接的 json 响应提取数据:https://www.bienici.com/recherche/achat/france?page=2
我有两个问题: - 首先,我想获取房屋的参数,例如(价格、区域、城市、邮政编码),但我不知道怎么做? - 其次,我想创建一个循环,将所有页面一直到第 100 页
这是程序:
import requests
from pandas.io.json import json_normalize
import csv
payload = {'filters': '{"size":24,"from":0,"filterType":"buy","newProperty":false,"page":2,"resultsPerPage":24,"maxAuthorizedResults":2400,"sortBy":"relevance","sortOrder":"desc","onTheMarket":[true],"limit":"ih{eIzjhZ?q}qrAzaf}AlrD?rvfrA","showAllModels":false,"blurInfoType":["disk","exact"]}'}
url = 'https://www.bienici.com/realEstateAds.json'
response = requests.get(url, params = payload).json()
with open("selog.csv", "w", newline="") as f:
writer = csv.writer(f)
for prop in response['realEstateAds']:
title = prop['title']
city = prop['city']
desc = prop['description']
price = prop['price']
df = json_normalize(response['realEstateAds'])
df.to_csv('selog.csv', index=False)
writer.writerow([price,title,city,desc])
【问题讨论】:
标签: python html json web-scraping