Created
March 9, 2018 14:18
-
-
Save thayton/76ee55882eaf26c8a0de6a1a01ef023e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import time | |
import json | |
import requests | |
class Scraper(object): | |
def __init__(self): | |
self.url = 'http://preowned.ferrari.com/vdata' | |
self.session = requests.Session() | |
self.headers = { | |
'X-Requested-With': 'XMLHttpRequest', | |
} | |
self.payload = { | |
'search': json.dumps({ | |
"sumname":"filtered", | |
"return":"list", | |
"summary_fields_dynamic":[ | |
"make", | |
"sub_brand", | |
"class", | |
"model", | |
"body_type", | |
"price", | |
"odometer", | |
"metacolour", | |
"fuel", | |
"transmission", | |
"year", | |
"ranges", | |
"model_variant", | |
"equipment_meta" | |
], | |
"tree_type":"cl_lp-mo_bo-lp", | |
"currency_locale":"en_US", | |
"distance_unit":"mi", | |
"currency":"USD", | |
"lang":"en_gb", | |
"include_special_prices":"1", | |
"equipment_meta_uncombined":"1", | |
"project":{ | |
"ids.vin":"", | |
"ids.oracle_id":"", | |
"main_info.approved":"", | |
"main_info.make":"", | |
"main_info.reg_year":"", | |
"main_info.model":"", | |
"main_info.seo_url":"", | |
"main_info.price_special":"", | |
"dealer.dealer_url":"", | |
"dealer.phone":"", | |
"dealer.email":"", | |
"dealer.name":"", | |
"dealer.postcode":"", | |
"dealer.country":"", | |
"dealer.line_address":"", | |
"dealer.cms_id":"", | |
"dealer.code":"", | |
"dealer.town":"", | |
"translations.default.year_make_model":"", | |
"translations.default.price_formated":"", | |
"translations.default.colour_with_trim":"", | |
"translations.default.odometer":"", | |
"translations.default.fuel_string":"", | |
"translations.default.interior":"", | |
"translations.default.body_type":"", | |
"translations.default.capacity_string":"", | |
"translations.default.transmission":"", | |
"translations.default.colour":"", | |
"images.count":"", | |
"images.list_430.img_1":"", | |
"images.list_430.img_2":"" | |
}, | |
"order":[ | |
"priced" | |
], | |
"market":[ | |
"ferrari united states" | |
], | |
"hits":{ | |
"to":6 | |
} | |
}), | |
'totals_search': json.dumps({ | |
"sumname":"unfiltered", | |
"return":"count", | |
"summary_fields_dynamic":[ | |
"make", | |
"sub_brand", | |
"class", | |
"model", | |
"body_type", | |
"price", | |
"odometer", | |
"metacolour", | |
"fuel", | |
"transmission", | |
"year", | |
"ranges", | |
"model_variant", | |
"equipment_meta" | |
], | |
"tree_type":"cl_lp-mo_bo-lp", | |
"currency_locale":"en_US", | |
"distance_unit":"mi", | |
"currency":"USD", | |
"lang":"en_gb", | |
"include_special_prices":"1", | |
"equipment_meta_uncombined":"1", | |
"market":[ | |
"ferrari united states" | |
] | |
}), | |
'timestamp': int(time.time()) | |
} | |
def scrape(self): | |
resp = self.session.post(self.url, headers=self.headers, data=self.payload) | |
data = resp.json() | |
print json.dumps(data, indent=2) | |
if __name__ == '__main__': | |
scraper = Scraper() | |
scraper.scrape() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment