5-4 Web Scraping Challenege#
Write a program to input a keyword like “tires” and then it will search https://syracuse.craigslist.org/search/ and create a dataframe with the following columns: title, price, location, and link.
The program should scrape the first page of the search results and create a dataframe with the results.
Approach#
We are going to need to make the scraper independent of the user interface
craigslist_scraper.py
def scrape_craigslist(search:str) -> list[dict]will input the search term and return a list of dictionaries with the results__name__ == "__main__"will useinput()to take the search term and then save the json file as{search}.jsonor output a JSON string viaprint()
craigslist_scraper_ui.py
will be a streamlit that inputs the search term
calls the
run_python_scriptfunction script to executecraigslist_scraper.pywith the search termreads the json fil or json string, deserializes, and displays the results in a dataframe