I'm using Python to scrape a real estate listings webpage. Currently I'm navigating to the site (https://www.mlslistings.com/), typing in a zip code into the search box, clicking 'search', and copy-pasting the resulting url into my script to be scraped.
Ultimately I'd like to loop over a list of zip codes, obtaining the url for each page to be scraped. So first I need to figure out how to do this once -- starting from the homepage, I'm hoping to access the page that follows the entry of a zip code into the search box.
I'm under the impression that this can be done using requests.post() together with a 'data' dictionary that points to the field I wish to populate and the corresponding input text.
I've tried
url = 'https://www.mlslistings.com'
data = {'input id': '94618'}
page = requests.post(url, data=data)
response = page.text
Here, I've used the key 'input id' based on inspecting the homepage and finding the search bar shows elements
<input id="searchText" type="text" name="searchText" class="form-control font-size-lg" placeholder="California City, Zip, Address, School District, MLS #" data-type="search" maxlength="300" aria-label="California City, Zip, Address, School District, MLS #" autocomplete="off">
I expected the resulting response object to be the html document containing the information displayed on the page obtained when I manually search for '94618' in my browser. Instead, it looks like the html document of the homepage itself.
Am I incorrectly naming the key in the data dictionary, or going wrong somewhere else? Any help would be greatly appreciated.