@rent-scraper/api 1.0.20 → 1.0.22

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/index.mjs +5 -5
  2. package/package.json +2 -2
package/dist/index.mjs CHANGED
@@ -1,8 +1,8 @@
1
- import g from"dayjs";import*as M from"cheerio";import{getValueFromConfigFile as F}from"@rent-scraper/utils/config";import{throwError as h,parseError as O,getRandomArrayValue as Z}from"@rent-scraper/utils";import{h as X,g as b,c as q}from"./shared/api.bGXs5gok.mjs";import y from"axios";import Y from"puppeteer";const N=async(e,t)=>{const{fromFile:r=!0}=t??{};return r?(await F("redfin","regionIds"))[String(e)]??await P(e):await P(e)},u=e=>JSON.parse(e.replace("{}&&","")),P=async e=>{const t="https://www.redfin.com/stingray/do/rental-location-autocomplete",r={"Content-Type":"application/json; charset=utf-8","User-Agent":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/136.0.0.0 Safari/537.36"},o=`?location=${e}&v=2`;try{const a=`${t}${o}`,n=await(await fetch(a,{method:"GET",headers:r})).text(),i=u(n),{exactMatch:s}=i.payload||{},p=Number(s.id.replace(s.type,"").replace("_",""));return p||console.log("no region id found for zip"),p}catch{return console.log("zip code not found"),null}},$=async e=>({data:await R(e)}),H=async e=>{const t=await R(e);return v(t)},v=e=>{const t=M.load(e)('script:contains("ReactServerAgent.cache")').text()?.replace(`_tLAB.wait(function(){
1
+ import g from"dayjs";import*as M from"cheerio";import{getValueFromConfigFile as F,updateConfigFile as Z}from"@rent-scraper/utils/config";import{throwError as h,parseError as O,getRandomArrayValue as X}from"@rent-scraper/utils";import{h as q,g as b,c as Y}from"./shared/api.bGXs5gok.mjs";import y from"axios";import $ from"puppeteer";const N=async(e,t)=>{const{fromFile:r=!0}=t??{};return r?(await F("redfin","regionIds"))[String(e)]??await P(e):await P(e)},u=e=>JSON.parse(e.replace("{}&&","")),P=async e=>{const t="https://www.redfin.com/stingray/do/rental-location-autocomplete",r={"Content-Type":"application/json; charset=utf-8","User-Agent":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/136.0.0.0 Safari/537.36"},o=`?location=${e}&v=2`;try{const a=`${t}${o}`,i=await(await fetch(a,{method:"GET",headers:r})).text(),n=u(i),{exactMatch:s}=n.payload||{},l=Number(s.id.replace(s.type,"").replace("_",""));return l||console.log("no region id found for zip"),l}catch{return console.log("zip code not found"),null}},K=async e=>({data:await R(e)}),H=async e=>{const t=await R(e);return v(t)},v=e=>{const t=M.load(e)('script:contains("ReactServerAgent.cache")').text()?.replace(`_tLAB.wait(function(){
2
2
  (function (root) {
3
3
  /* -- Data -- */
4
4
  root.__reactServerState || (root.__reactServerState = {});
5
- root.__reactServerState.InitialContext = {"ReactServerAgent.cache":`,"")?.split(',"deviceType":"desktop"')[0],r=(t&&JSON.parse(t))?.dataCache,o=r?.["/stingray/api/home/details/initialInfo"]?.res?.text&&u(r["/stingray/api/home/details/initialInfo"].res.text)?.payload,a=o?.propertyId??o?.redirectUrl?.split("/").pop(),n=r?.[`/stingray/api/v1/rentals/homecards?propertyIds=${a}`]?.res?.text,i=n&&u(n),s=r?.["/stingray/api/home/details/belowTheFold"]?.res?.text,p=s&&u(s)?.payload,l=r?.[`/stingray/api/home/details/propertyParcelInfo?propertyId=${a}&pageType=6`]?.res?.text,_=l&&u(l)?.payload,d=i?.homes?.[0]?.rentalExtension?.rentalId,c=r?.[`/stingray/api/v1/rentals/${d}/floorPlans?`]?.res?.text,T=c&&u(c),m={hasPropertyHistory:!!p?.propertyHistoryInfo,propertyId:a,rentalId:d,initialInfo:o,homeCards:i,floorPlans:T,belowTheFold:p,propertyParcelInfo:_};return{timestamp:g(),...m}},R=async(e,t)=>{const{timeoutMs:r}=t??{},o=await X(),a={headers:{"Content-Type":"text/html; charset=utf-8","User-Agent":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/136.0.0.0 Safari/537.36",...o&&{Cookie:o}},...r&&{signal:(i=>{const s=new AbortController;return setTimeout(()=>s.abort(),i||0),s.signal})(r)}},n=await fetch(e,a);if(n.status===202&&h(`Redfin bot filtering (202) for ${e} \u2014 restart the browser server to refresh the cookie.`),n.ok)return await n.text();{const i=await n.text().catch(()=>""),s=(i&&JSON.parse(i)?.error)??`${n.status} ${n.statusText}`;h(s)}},K=async(e,t)=>await H(t??`https://www.redfin.com/us/home/${e}`),Q=async({regionId:e,zipCode:t,timeoutMs:r,daysListed:o})=>{t&&(e=await N(t)??e);try{const a=await V({regionId:e,timeoutMs:r}),n=a?.numMatchedHomes,i=o?a?.homes?.filter(l=>g().diff(l?.rentalExtension?.freshnessTimestamp,"day")<o):a?.homes,s=i?.map(l=>l?.detailUrl),p=i?.length;return p?{timestamp:g(),...t&&{zipCode:t},regionId:e,numResults:p,totalResultCount:n,results:i,urls:s}:null}catch(a){throw console.log(a),a}},V=async({regionId:e,timeoutMs:t})=>{const r="https://www.redfin.com/stingray/api/v1/search/rentals",o={"Content-Type":"application/json; charset=utf-8","User-Agent":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/136.0.0.0 Safari/537.36"},a=`?al=1&isRentals=true&market=socal&num_homes=350&ord=days-on-redfin-asc&page_number=1&region_id=${e}&region_type=2&sf=1,2,3,5,6,7&start=0&status=9&uipt=1,2,3,4&use_max_pins=true&v=8`,n={headers:o,...t&&{signal:(s=>{const p=new AbortController;return setTimeout(()=>p.abort(),s||0),p.signal})(t)}},i=`${r}${a}`;return await(await fetch(i,n)).json()},B=async(e,t)=>{const{fromFile:r=!0}=t??{};return r?(await F("zillow","regionIds"))[String(e)]??await U(e):await U(e)},U=async e=>{const t="https://www.zillow.com/graphql",r={operationName:"getAutocompleteResults",variables:{query:String(e),queryOptions:{maxResults:10,userIdentity:{abKey:"3176854b-962d-4266-8bb8-f9e8f2377158"},userSearchContext:"FOR_RENT",userLocation:{latitude:34.11,longitude:-118.23}},resultType:["REGIONS","FORSALE","RENTALS","SOLD","COMMUNITIES","BUILDER_COMMUNITIES"]},query:`query getAutocompleteResults($query: String!, $queryOptions: SearchAssistanceQueryOptions, $resultType: [SearchAssistanceResultType]) {
5
+ root.__reactServerState.InitialContext = {"ReactServerAgent.cache":`,"")?.split(',"deviceType":"desktop"')[0],r=(t&&JSON.parse(t))?.dataCache,o=r?.["/stingray/api/home/details/initialInfo"]?.res?.text&&u(r["/stingray/api/home/details/initialInfo"].res.text)?.payload,a=o?.propertyId??o?.redirectUrl?.split("/").pop(),i=r?.[`/stingray/api/v1/rentals/homecards?propertyIds=${a}`]?.res?.text,n=i&&u(i),s=r?.["/stingray/api/home/details/belowTheFold"]?.res?.text,l=s&&u(s)?.payload,p=r?.[`/stingray/api/home/details/propertyParcelInfo?propertyId=${a}&pageType=6`]?.res?.text,_=p&&u(p)?.payload,d=n?.homes?.[0]?.rentalExtension?.rentalId,c=r?.[`/stingray/api/v1/rentals/${d}/floorPlans?`]?.res?.text,T=c&&u(c),m={hasPropertyHistory:!!l?.propertyHistoryInfo,propertyId:a,rentalId:d,initialInfo:o,homeCards:n,floorPlans:T,belowTheFold:l,propertyParcelInfo:_};return{timestamp:g(),...m}},R=async(e,t)=>{const{timeoutMs:r}=t??{},o=await q(),a={headers:{"Content-Type":"text/html; charset=utf-8","User-Agent":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/136.0.0.0 Safari/537.36",...o&&{Cookie:o}},...r&&{signal:(n=>{const s=new AbortController;return setTimeout(()=>s.abort(),n||0),s.signal})(r)}},i=await fetch(e,a);if(i.status===202&&h(`Redfin bot filtering (202) for ${e} \u2014 restart the browser server to refresh the cookie.`),i.ok)return await i.text();{const n=await i.text().catch(()=>""),s=(n&&JSON.parse(n)?.error)??`${i.status} ${i.statusText}`;h(s)}},Q=async(e,t)=>await H(t??`https://www.redfin.com/us/home/${e}`),j=async({regionId:e,zipCode:t,timeoutMs:r,daysListed:o})=>{t&&(e=await N(t)??e);try{const a=await V({regionId:e,timeoutMs:r}),i=a?.numMatchedHomes,n=o?a?.homes?.filter(p=>g().diff(p?.rentalExtension?.freshnessTimestamp,"day")<o):a?.homes,s=n?.map(p=>p?.detailUrl),l=n?.length;return l?{timestamp:g(),...t&&{zipCode:t},regionId:e,numResults:l,totalResultCount:i,results:n,urls:s}:null}catch(a){throw console.log(a),a}},V=async({regionId:e,timeoutMs:t})=>{const r="https://www.redfin.com/stingray/api/v1/search/rentals",o={"Content-Type":"application/json; charset=utf-8","User-Agent":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/136.0.0.0 Safari/537.36"},a=`?al=1&isRentals=true&market=socal&num_homes=350&ord=days-on-redfin-asc&page_number=1&region_id=${e}&region_type=2&sf=1,2,3,5,6,7&start=0&status=9&uipt=1,2,3,4&use_max_pins=true&v=8`,i={headers:o,...t&&{signal:(s=>{const l=new AbortController;return setTimeout(()=>l.abort(),s||0),l.signal})(t)}},n=`${r}${a}`;return await(await fetch(n,i)).json()},B=async(e,t)=>{const{fromFile:r=!0}=t??{};if(r){const o=await F("zillow","regionIds")??{},a=o[String(e)];if(a!=null)return a;const i=await U(e);return i!=null&&await Z("zillow",{regionIds:{...o,[String(e)]:i}}),i}else return await U(e)},U=async e=>{const t="https://www.zillow.com/graphql",r={operationName:"getAutocompleteResults",variables:{query:String(e),queryOptions:{maxResults:10,userIdentity:{abKey:"3176854b-962d-4266-8bb8-f9e8f2377158"},userSearchContext:"FOR_RENT",userLocation:{latitude:34.11,longitude:-118.23}},resultType:["REGIONS","FORSALE","RENTALS","SOLD","COMMUNITIES","BUILDER_COMMUNITIES"]},query:`query getAutocompleteResults($query: String!, $queryOptions: SearchAssistanceQueryOptions, $resultType: [SearchAssistanceResultType]) {
6
6
  searchAssistanceResult: zgsAutocompleteRequest(
7
7
  query: $query
8
8
  queryOptions: $queryOptions
@@ -129,7 +129,7 @@ fragment RentalCommunityResultFields on SearchAssistanceRentalCommunityResult {
129
129
  fragment BuilderCommunityResultFields on SearchAssistanceBuilderCommunityResult {
130
130
  plid
131
131
  __typename
132
- }`},o={accept:"*/*","accept-encoding":"gzip, deflate, br, zstd","accept-language":"en-US,en;q=0.7","client-id":"hops-homepage","content-type":"application/json",origin:"https://www.zillow.com",priority:"u=1, i",referer:"https://www.zillow.com/","sec-ch-ua":'"Google Chrome";v="136", "Not(A:Brand";v="8", "Chromium";v="136"',"sec-ch-ua-mobile":"?0","sec-ch-ua-platform":'"macOS"',"user-agent":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/136.0.0.0 Safari/537.36","sec-fetch-site":"same-origin","sec-fetch-dest":"empty","sec-fetch-mode":"cors",cookie:await b()};try{const{data:a}=await y.post(t,r,{headers:o})||{},{regionId:n}=a.data.searchAssistanceResult.results.filter(i=>i?.regionId)?.[0]||{};return n||console.log("no region id found for zip"),n}catch(a){const{status:n,message:i}=O(a)??{};if(E(n,i))h(i,n);else return console.log("zip code not found"),null}},G={Accept:"*/*","Accept-Language":"en-US,en;q=0.9","Content-Type":"application/json","Cache-Control":"no-cache",Pragma:"no-cache","Sec-Ch-Ua":'"Google Chrome";v="136", "Not(A:Brand";v="8", "Chromium";v="136"',"Sec-Ch-Ua-Mobile":"?0","Sec-Ch-Ua-Platform":'"macOS"',"Sec-Fetch-Dest":"empty","Sec-Fetch-Mode":"cors","Sec-Fetch-Site":"same-origin","Sec-Fetch-User":"?1","Upgrade-Insecure-Requests":"1","User-Agent":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/136.0.0.0 Safari/537.36"},x=async({page:e,daysOnZillow:t,regionId:r,zipCode:o,mergePageResults:a,timeoutMs:n})=>{o&&(r=await B(o)??r),e=(a?1:e)??1;const i=await f({page:e,daysOnZillow:t,regionId:r,timeoutMs:n}),s=i?.cat1?.searchList?.totalResultCount,p=i?.cat1?.searchList?.resultsPerPage,l=i?.cat1?.searchList?.totalPages;if(e&&e>l)return null;const _=a&&Array.from({length:l},(m,I)=>I+1),d=a&&l>1&&_?(await Promise.all(_?.map(async m=>await f({page:m,daysOnZillow:t,regionId:r},!0)))).flat():i?.cat1?.searchResults?.listResults,c=d?.map(m=>m?.detailUrl),T=d?.length;return T?{timestamp:g(),...o&&{zipCode:o},regionId:r,numResults:T,totalResultCount:s,resultsPerPage:p,...a&&{mergePageResults:a},..._?{pagesCrawled:_?.length}:{page:e},totalPages:l,results:d,urls:c}:null},f=async({page:e,daysOnZillow:t,regionId:r,timeoutMs:o},a)=>{const n="https://www.zillow.com/async-create-search-page-state",i={searchQueryState:{pagination:{currentPage:e??1},isMapVisible:!1,mapBounds:{east:-116.2057669921875,north:35.424914784130365,south:32.12915408246069,west:-120.3915580078125},regionSelection:[{regionId:r}],filterState:{sortSelection:{value:"days"},doz:{value:String(t??5)},isNewConstruction:{value:!1},isForSaleForeclosure:{value:!1},isForSaleByOwner:{value:!1},isForSaleByAgent:{value:!1},isForRent:{value:!0},isComingSoon:{value:!1},isAuction:{value:!1},isAllHomes:{value:!0}},isListVisible:!0},wants:{cat1:["listResults"]},requestId:6,isDebugRequest:!1},s=d=>{const c=new AbortController;return setTimeout(()=>c.abort(),d||0),c.signal},p=await b(),l={headers:{...G,cookie:p},...o&&{signal:s(o)}},{data:_}=await y.put(n,i,l)||{};return a?_?.cat1?.searchResults?.listResults:_},S=async(e,t)=>{const{timeoutMs:r}=t??{},o={headers:{Host:"www.zillow.com",accept:"*/*","content-type":"text/html; charset=utf-8","user-agent":"insomnia/10.3.0"},...r&&{signal:(n=>{const i=new AbortController;return setTimeout(()=>i.abort(),n||0),i.signal})(r)}},{data:a}=await y.options(e,o)||{};return a},j=async e=>({data:await S(e)}),J=async e=>{const t=await S(e);return z(t)},ee=(e,t)=>{if(t==="building")return e?.initialReduxState?.gdp?.building??null;{e=e&&JSON.parse(e?.gdpClientCache);const r=e&&Object.keys(e)?.[0];return e=e?.[r]?.property,e??null}},z=e=>{const t=M.load(e)("#__NEXT_DATA__").text(),r=t&&JSON.parse(t)?.props?.pageProps?.componentProps,o=r?.initialReduxState?.gdp?"building":"property",a=ee(r,o);return{timestamp:g(),...a}},w={accept:"*/*","accept-encoding":"gzip, deflate, br, zstd","accept-language":"en-US,en;q=0.9","client-id":"for-sale-sub-app-browser-client","content-type":"application/json","Cache-Control":"no-cache",Pragma:"no-cache",priority:"u=1, i","sec-ch-ua":'"Google Chrome";v="136", "Not(A:Brand";v="8", "Chromium";v="136"',"sec-ch-ua-mobile":"?0","sec-ch-ua-platform":'"macOS"',"sec-fetch-dest":"empty","sec-fetch-mode":"cors","sec-fetch-site":"same-origin","user-agent":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/136.0.0.0 Safari/537.36","x-z-enable-oauth-conversion":"true"},k=async(e,t)=>{const{altFetch:r,onlyRemovedListings:o=!1}=t??{},a=(r?await re(e,t):await te(e,t))||{},{property:n,...i}=a;if(n){const{buyAbilityData:s,collections:p,nearbyCities:l,nearbyNeighborhoods:_,nearbyZipcodes:d,schools:c,nearbyHomes:T,listingMetadata:m,homeInsights:I,responsivePhotos:le,submitFlow:_e,contactFormRenderData:de,tourEligibility:ce,onsiteMessage:me,ZoDsFsUpsellTop:ye,streetViewMetadataUrlMapLightboxAddress:ue,responsivePhotosOriginalRatio:ge,thirdPartyVirtualTour:he,vrModel:Te,topNavJson:Ae,...A}=n||{};if(!A?.priceHistory)return null;if(o){const{homeStatus:D}=A??{};if(!D)return console.log("no home status",e),null;if(D==="FOR_RENT"){const[L]=A?.priceHistory??{};return L?.event?console.log("recent price history not removed",e,L?.event):console.log("no recent price history"),null}}return{timestamp:g(),...A,...i,...r&&{altFetch:r}}}},te=async(e,t)=>{const{timeoutMs:r}=t??{},o="https://www.zillow.com/graphql",a=`?extensions=%7B%22persistedQuery%22%3A%7B%22version%22%3A1%2C%22sha256Hash%22%3A%222a50ebbffc7b6fb6e70fad24b7738df5db7f2ed5b61c2b980542749accff1f17%22%7D%7D&variables=%7B%22zpid%22%3A${e}%2C%22platform%22%3A%22DESKTOP_WEB%22%2C%22formType%22%3A%22OPAQUE%22%2C%22contactFormRenderParameter%22%3A%7B%22zpid%22%3A${e}%2C%22platform%22%3A%22desktop%22%2C%22isDoubleScroll%22%3Atrue%7D%2C%22skipCFRD%22%3Afalse%2C%22ompPlatform%22%3A%22web%22%7D`,n=`${o}${a}`,i=_=>{const d=new AbortController;return setTimeout(()=>d.abort(),_||0),d.signal},s=await b(),p={headers:{...w,cookie:s},...r&&{signal:i(r)}},{data:l}=await y.get(n,p)||{};return l?.data},re=async(e,{timeoutMs:t})=>{const r="https://www.zillow.com/graphql",o={operationName:"ForRentShopperPlatformFullRenderQuery",variables:{zpid:e,altId:null},query:`query ForRentShopperPlatformFullRenderQuery($zpid: ID!, $altId: ID, $skipPropertyPrice: Boolean = false, $skipPropertyAddress: Boolean = false) {
132
+ }`},o={accept:"*/*","accept-encoding":"gzip, deflate, br, zstd","accept-language":"en-US,en;q=0.7","client-id":"hops-homepage","content-type":"application/json",origin:"https://www.zillow.com",priority:"u=1, i",referer:"https://www.zillow.com/","sec-ch-ua":'"Google Chrome";v="136", "Not(A:Brand";v="8", "Chromium";v="136"',"sec-ch-ua-mobile":"?0","sec-ch-ua-platform":'"macOS"',"user-agent":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/136.0.0.0 Safari/537.36","sec-fetch-site":"same-origin","sec-fetch-dest":"empty","sec-fetch-mode":"cors",cookie:await b()};try{const{data:a}=await y.post(t,r,{headers:o})||{},{regionId:i}=a.data.searchAssistanceResult.results.filter(n=>n?.regionId)?.[0]||{};return i||console.log("no region id found for zip"),i}catch(a){const{status:i,message:n}=O(a)??{};if(E(i,n))h(n,i);else return console.log("zip code not found"),null}},G={Accept:"*/*","Accept-Language":"en-US,en;q=0.9","Content-Type":"application/json","Cache-Control":"no-cache",Pragma:"no-cache","Sec-Ch-Ua":'"Google Chrome";v="136", "Not(A:Brand";v="8", "Chromium";v="136"',"Sec-Ch-Ua-Mobile":"?0","Sec-Ch-Ua-Platform":'"macOS"',"Sec-Fetch-Dest":"empty","Sec-Fetch-Mode":"cors","Sec-Fetch-Site":"same-origin","Sec-Fetch-User":"?1","Upgrade-Insecure-Requests":"1","User-Agent":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/136.0.0.0 Safari/537.36"},x=async({page:e,daysOnZillow:t,regionId:r,zipCode:o,mergePageResults:a,timeoutMs:i})=>{o&&(r=await B(o)??r),e=(a?1:e)??1;const n=await f({page:e,daysOnZillow:t,regionId:r,timeoutMs:i}),s=n?.cat1?.searchList?.totalResultCount,l=n?.cat1?.searchList?.resultsPerPage,p=n?.cat1?.searchList?.totalPages;if(e&&e>p)return null;const _=a&&Array.from({length:p},(m,I)=>I+1),d=a&&p>1&&_?(await Promise.all(_?.map(async m=>await f({page:m,daysOnZillow:t,regionId:r},!0)))).flat():n?.cat1?.searchResults?.listResults,c=d?.map(m=>m?.detailUrl),T=d?.length;return T?{timestamp:g(),...o&&{zipCode:o},regionId:r,numResults:T,totalResultCount:s,resultsPerPage:l,...a&&{mergePageResults:a},..._?{pagesCrawled:_?.length}:{page:e},totalPages:p,results:d,urls:c}:null},f=async({page:e,daysOnZillow:t,regionId:r,timeoutMs:o},a)=>{const i="https://www.zillow.com/async-create-search-page-state",n={searchQueryState:{pagination:{currentPage:e??1},isMapVisible:!1,mapBounds:{east:-116.2057669921875,north:35.424914784130365,south:32.12915408246069,west:-120.3915580078125},regionSelection:[{regionId:r}],filterState:{sortSelection:{value:"days"},doz:{value:String(t??5)},isNewConstruction:{value:!1},isForSaleForeclosure:{value:!1},isForSaleByOwner:{value:!1},isForSaleByAgent:{value:!1},isForRent:{value:!0},isComingSoon:{value:!1},isAuction:{value:!1},isAllHomes:{value:!0}},isListVisible:!0},wants:{cat1:["listResults"]},requestId:6,isDebugRequest:!1},s=d=>{const c=new AbortController;return setTimeout(()=>c.abort(),d||0),c.signal},l=await b(),p={headers:{...G,cookie:l},...o&&{signal:s(o)}},{data:_}=await y.put(i,n,p)||{};return a?_?.cat1?.searchResults?.listResults:_},S=async(e,t)=>{const{timeoutMs:r}=t??{},o={headers:{Host:"www.zillow.com",accept:"*/*","content-type":"text/html; charset=utf-8","user-agent":"insomnia/10.3.0"},...r&&{signal:(i=>{const n=new AbortController;return setTimeout(()=>n.abort(),i||0),n.signal})(r)}},{data:a}=await y.options(e,o)||{};return a},J=async e=>({data:await S(e)}),ee=async e=>{const t=await S(e);return z(t)},te=(e,t)=>{if(t==="building")return e?.initialReduxState?.gdp?.building??null;{e=e&&JSON.parse(e?.gdpClientCache);const r=e&&Object.keys(e)?.[0];return e=e?.[r]?.property,e??null}},z=e=>{const t=M.load(e)("#__NEXT_DATA__").text(),r=t&&JSON.parse(t)?.props?.pageProps?.componentProps,o=r?.initialReduxState?.gdp?"building":"property",a=te(r,o);return{timestamp:g(),...a}},w={accept:"*/*","accept-encoding":"gzip, deflate, br, zstd","accept-language":"en-US,en;q=0.9","client-id":"for-sale-sub-app-browser-client","content-type":"application/json","Cache-Control":"no-cache",Pragma:"no-cache",priority:"u=1, i","sec-ch-ua":'"Google Chrome";v="136", "Not(A:Brand";v="8", "Chromium";v="136"',"sec-ch-ua-mobile":"?0","sec-ch-ua-platform":'"macOS"',"sec-fetch-dest":"empty","sec-fetch-mode":"cors","sec-fetch-site":"same-origin","user-agent":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/136.0.0.0 Safari/537.36","x-z-enable-oauth-conversion":"true"},k=async(e,t)=>{const{altFetch:r,onlyRemovedListings:o=!1}=t??{},a=(r?await oe(e,t):await re(e,t))||{},{property:i,...n}=a;if(i){const{buyAbilityData:s,collections:l,nearbyCities:p,nearbyNeighborhoods:_,nearbyZipcodes:d,schools:c,nearbyHomes:T,listingMetadata:m,homeInsights:I,responsivePhotos:_e,submitFlow:de,contactFormRenderData:ce,tourEligibility:me,onsiteMessage:ye,ZoDsFsUpsellTop:ue,streetViewMetadataUrlMapLightboxAddress:ge,responsivePhotosOriginalRatio:he,thirdPartyVirtualTour:Te,vrModel:Ae,topNavJson:be,...A}=i||{};if(!A?.priceHistory)return null;if(o){const{homeStatus:D}=A??{};if(!D)return console.log("no home status",e),null;if(D==="FOR_RENT"){const[L]=A?.priceHistory??{};return L?.event?console.log("recent price history not removed",e,L?.event):console.log("no recent price history"),null}}return{timestamp:g(),...A,...n,...r&&{altFetch:r}}}},re=async(e,t)=>{const{timeoutMs:r}=t??{},o="https://www.zillow.com/graphql",a=`?extensions=%7B%22persistedQuery%22%3A%7B%22version%22%3A1%2C%22sha256Hash%22%3A%222a50ebbffc7b6fb6e70fad24b7738df5db7f2ed5b61c2b980542749accff1f17%22%7D%7D&variables=%7B%22zpid%22%3A${e}%2C%22platform%22%3A%22DESKTOP_WEB%22%2C%22formType%22%3A%22OPAQUE%22%2C%22contactFormRenderParameter%22%3A%7B%22zpid%22%3A${e}%2C%22platform%22%3A%22desktop%22%2C%22isDoubleScroll%22%3Atrue%7D%2C%22skipCFRD%22%3Afalse%2C%22ompPlatform%22%3A%22web%22%7D`,i=`${o}${a}`,n=_=>{const d=new AbortController;return setTimeout(()=>d.abort(),_||0),d.signal},s=await b(),l={headers:{...w,cookie:s},...r&&{signal:n(r)}},{data:p}=await y.get(i,l)||{};return p?.data},oe=async(e,{timeoutMs:t})=>{const r="https://www.zillow.com/graphql",o={operationName:"ForRentShopperPlatformFullRenderQuery",variables:{zpid:e,altId:null},query:`query ForRentShopperPlatformFullRenderQuery($zpid: ID!, $altId: ID, $skipPropertyPrice: Boolean = false, $skipPropertyAddress: Boolean = false) {
133
133
  property(zpid: $zpid, palsId: $altId) {
134
134
  ...FrActionBarContent_property
135
135
  ...FrMediaColumnContent_property
@@ -2398,7 +2398,7 @@ fragment ForRentSearchPageStateParamsFragment_property on Property {
2398
2398
  fragment RentalPrequalificationCard on ABTests {
2399
2399
  RC_QUALIFICATION_FLOW: abTest(trial: "RC_QUALIFICATION_FLOW")
2400
2400
  }
2401
- `},a=p=>{const l=new AbortController;return setTimeout(()=>l.abort(),p||0),l.signal},n=await b(),i={headers:{...w,cookie:n},...t&&{signal:a(t)}},{data:s}=await y.post(r,o,i)||{};return s?.data},oe=async e=>{const t="https://www.zillow.com/graphql",r={operationName:"ListingContactDetailsQuery",variables:{zpid:e,altId:null},query:`query ListingContactDetailsQuery($zpid: ID!, $altId: ID) {
2401
+ `},a=l=>{const p=new AbortController;return setTimeout(()=>p.abort(),l||0),p.signal},i=await b(),n={headers:{...w,cookie:i},...t&&{signal:a(t)}},{data:s}=await y.post(r,o,n)||{};return s?.data},ae=async e=>{const t="https://www.zillow.com/graphql",r={operationName:"ListingContactDetailsQuery",variables:{zpid:e,altId:null},query:`query ListingContactDetailsQuery($zpid: ID!, $altId: ID) {
2402
2402
  viewer {
2403
2403
  roles {
2404
2404
  isLandlordLiaisonMember
@@ -2458,4 +2458,4 @@ fragment RentalPrequalificationCard on ABTests {
2458
2458
  }
2459
2459
  }
2460
2460
  }
2461
- `},{data:o}=await y.post(t,r,{headers:w})||{};return o?.data?.property},E=(e,t)=>e===403&&t?.includes("captcha"),ae=e=>Z(e),ie=async e=>{await y.post("http://localhost:8082/browser/open",{url:e})},C=async(e,t=0)=>{try{await q()||h("zip codes required, please run the createConfig script");const{fetchListings:r=!1}=e??{},o=3101,{results:a}=await x({regionId:o,daysOnZillow:1,mergePageResults:!1})??{},{zpid:n,detailUrl:i}=a?.[0]??{};return n&&r?await k(n):a?.length&&!r||(i&&!i.startsWith("/apartments")?await S(i):t<5?await C(e,t+1):h("Could not find a valid listing URL to check for bot filtering.")),!0}catch(r){const{status:o,message:a}=O(r);E(o,a)&&h("Zillow bot filtering! Please open https://zillow.com in your browser and complete the challenge to continue.")}},ne=async()=>await new Promise(e=>{const t=setInterval(async()=>{try{await ie("https://www.zillow.com/homes/for_rent/");const r=await C();r&&(e(r),clearInterval(t))}catch{}},500)}),W=()=>{const e=["Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36","Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36","Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36","Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36","Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36","Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.1 Safari/605.1.15","Mozilla/5.0 (Macintosh; Intel Mac OS X 13_1) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.1 Safari/605.1.15"],t=Math.floor(Math.random()*e.length);return e[t]},se=async(e,t)=>{const r=await Y.launch({headless:!0,timeout:1e5,defaultViewport:null}),o=await r.newPage();if(e.includes("file://"))await o.setJavaScriptEnabled(!1);else{const n=W();await o.setUserAgent(n)}await o.goto(e,{waitUntil:"networkidle2"});const a=await o.evaluate(()=>document.querySelector(".layout-content-container")?.clientHeight);a&&await o.setViewport({width:1024,height:a}),await o.screenshot({path:t,fullPage:!0,captureBeyondViewport:!0}),await o.close(),await r.close(),console.log(`screenshot complete, ${t}`)},pe=e=>{if(e==null||typeof e!="object")return!1;const t=e;return!(t.address===void 0||typeof t.bedrooms!="number"||typeof t.bedrooms!="number"||typeof t.daysOnZillow!="number"||typeof t.hdpUrl!="string"||typeof t.homeStatus!="string"||typeof t.homeType!="string"||typeof t.isRentalListingOffMarket!="boolean"||typeof t.price!="number"||typeof t.timeOnZillow!="string"||typeof t.zipcode!="string"||typeof t.zpid!="number")};export{C as checkForZillowBotFiltering,R as fetchHtmlFromRedfinListingUrl,S as fetchHtmlFromZillowListingUrl,V as fetchRedfinListingResults,P as fetchRedfinRegionIdByZipCode,f as fetchZillowListingResults,W as generateRandomUA,$ as getHtmlFromRedfinListingUrl,j as getHtmlFromZillowListingUrl,ae as getRandomZipCode,K as getRedfinListingDetailsById,Q as getRedfinListingResults,N as getRedfinRegionIdByZipCode,oe as getZillowListingContactDetailsByZpid,k as getZillowListingDetailsByZpid,x as getZillowListingResults,B as getZillowRegionIdByZipCode,E as isZillowBotFiltering,pe as isZillowListingForRow,u as parseRedfinResponse,v as scrapeDataFromRedfinListingHtml,H as scrapeDataFromRedfinListingUrl,z as scrapeDataFromZillowListingHtml,J as scrapeDataFromZillowListingUrl,se as screenshotZillowListing,ne as waitForSolvedZillowCaptcha,G as zillowListingResultsHeaders};
2461
+ `},{data:o}=await y.post(t,r,{headers:w})||{};return o?.data?.property},E=(e,t)=>e===403&&t?.includes("captcha"),ie=e=>X(e),ne=async e=>{await y.post("http://localhost:8082/browser/open",{url:e})},C=async(e,t=0)=>{try{await Y()||h("zip codes required, please run the createConfig script");const{fetchListings:r=!1}=e??{},o=3101,{results:a}=await x({regionId:o,daysOnZillow:1,mergePageResults:!1})??{},{zpid:i,detailUrl:n}=a?.[0]??{};return i&&r?await k(i):a?.length&&!r||(n&&!n.startsWith("/apartments")?await S(n):t<5?await C(e,t+1):h("Could not find a valid listing URL to check for bot filtering.")),!0}catch(r){const{status:o,message:a}=O(r);E(o,a)&&h("Zillow bot filtering! Please open https://zillow.com in your browser and complete the challenge to continue.")}},se=async()=>await new Promise(e=>{const t=setInterval(async()=>{try{await ne("https://www.zillow.com/homes/for_rent/");const r=await C();r&&(e(r),clearInterval(t))}catch{}},500)}),W=()=>{const e=["Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36","Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36","Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36","Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36","Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36","Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.1 Safari/605.1.15","Mozilla/5.0 (Macintosh; Intel Mac OS X 13_1) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.1 Safari/605.1.15"],t=Math.floor(Math.random()*e.length);return e[t]},le=async(e,t)=>{const r=await $.launch({headless:!0,timeout:1e5,defaultViewport:null}),o=await r.newPage();if(e.includes("file://"))await o.setJavaScriptEnabled(!1);else{const i=W();await o.setUserAgent(i)}await o.goto(e,{waitUntil:"networkidle2"});const a=await o.evaluate(()=>document.querySelector(".layout-content-container")?.clientHeight);a&&await o.setViewport({width:1024,height:a}),await o.screenshot({path:t,fullPage:!0,captureBeyondViewport:!0}),await o.close(),await r.close(),console.log(`screenshot complete, ${t}`)},pe=e=>{if(e==null||typeof e!="object")return!1;const t=e;return!(t.address===void 0||typeof t.bedrooms!="number"||typeof t.bedrooms!="number"||typeof t.daysOnZillow!="number"||typeof t.hdpUrl!="string"||typeof t.homeStatus!="string"||typeof t.homeType!="string"||typeof t.isRentalListingOffMarket!="boolean"||typeof t.price!="number"||typeof t.timeOnZillow!="string"||typeof t.zipcode!="string"||typeof t.zpid!="number")};export{C as checkForZillowBotFiltering,R as fetchHtmlFromRedfinListingUrl,S as fetchHtmlFromZillowListingUrl,V as fetchRedfinListingResults,P as fetchRedfinRegionIdByZipCode,f as fetchZillowListingResults,W as generateRandomUA,K as getHtmlFromRedfinListingUrl,J as getHtmlFromZillowListingUrl,ie as getRandomZipCode,Q as getRedfinListingDetailsById,j as getRedfinListingResults,N as getRedfinRegionIdByZipCode,ae as getZillowListingContactDetailsByZpid,k as getZillowListingDetailsByZpid,x as getZillowListingResults,B as getZillowRegionIdByZipCode,E as isZillowBotFiltering,pe as isZillowListingForRow,u as parseRedfinResponse,v as scrapeDataFromRedfinListingHtml,H as scrapeDataFromRedfinListingUrl,z as scrapeDataFromZillowListingHtml,ee as scrapeDataFromZillowListingUrl,le as screenshotZillowListing,se as waitForSolvedZillowCaptcha,G as zillowListingResultsHeaders};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rent-scraper/api",
3
- "version": "1.0.20",
3
+ "version": "1.0.22",
4
4
  "type": "module",
5
5
  "main": "./dist/index.mjs",
6
6
  "module": "./dist/index.mjs",
@@ -31,7 +31,7 @@
31
31
  "cheerio": "^1.1.0",
32
32
  "dayjs": "^1.11.13",
33
33
  "puppeteer": "^24.11.2",
34
- "@rent-scraper/utils": "1.0.20"
34
+ "@rent-scraper/utils": "1.0.22"
35
35
  },
36
36
  "devDependencies": {
37
37
  "unbuild": "^3.5.0",