I'm trying to parse different property links which are populated when I select two dropdowns from zillow. When I'm done choosing the options, I can see the results in json in dev tools. However, when I do the same using the script below, I get some weird text.
Manual actions:
- Navigated to that site
- Chose options from first dropdown
- Chose options from second dropdown
This is how I've tried to automate:
import json
import requests
from pprint import pprint
link = 'https://www.zillow.com/search/GetSearchPageState.htm?'
params = {
'searchQueryState': {"pagination":{},"usersSearchTerm":"Vista, CA","mapBounds":{"west":-117.44051346728516,"east":-116.99488053271484,"south":33.126944633035116,"north":33.27919773006566},"regionSelection":[{"regionId":41517,"regionType":6}],"isMapVisible":True,"filterState":{"doz":{"value":"6m"},"isForSaleByAgent":{"value":False},"isForSaleByOwner":{"value":False},"isNewConstruction":{"value":False},"isForSaleForeclosure":{"value":False},"isComingSoon":{"value":False},"isAuction":{"value":False},"isPreMarketForeclosure":{"value":False},"isPreMarketPreForeclosure":{"value":False},"isRecentlySold":{"value":True},"isAllHomes":{"value":True},"hasPool":{"value":True},"hasAirConditioning":{"value":True},"isApartmentOrCondo":{"value":False}},"isListVisible":True,"mapZoom":11},
'wants': {"cat1":["listResults","mapResults"]},
'requestId': 2
}
with requests.Session() as s:
s.headers['User-Agent'] = 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.150 Safari/537.36'
res = s.get(link,params=json.dumps(params))
pprint(res.content)
This is the output it produces:
b'<!-- This page outputs JSON instead of anything written here. -->'
How can I parse customized property links from zillow using requests?