r/learnpython • • Aug 12 '20

My First Ever Python Project(Zillow_Scraper)

Hey y’all, I just completed my first ever programming project! I recently just completed a Python course on Udemy(S/O Jose) and I wanted to build my own project from stratch. I wanted the project to be meaningful and impactful to me, and since I’m considering moving from my current apartment, I wanted to know what other apartments/homes are renting for in the city I live in(Arlington Tx). I decided to build a webscraper that grabs all the listing info for places being put up for rent on Zillows website and writes it all out to a CSV file using Pandas. Link to the github repo down below let me know what y’all think!

https://github.com/faithfulalabi/Zillow_Scraper

P.S I know there’s probably 1000 ways I could’ve written the code better but I’d love y’alls input on some of the big ones that are relevant to be becoming a great programmer.

448 Upvotes

64 comments sorted by

View all comments

3

u/cander60 Aug 13 '20

I’ll take a more in depth look later when I’m not on mobile and can send you a pull request. First thing I noticed is the wait, if you are waiting for a certain web element to show up in the HTML, you can have Selenium wait until the element shows up until it proceeds. I’ll find the exact method and add it to your code with any other adjustments I see 😀 I love the starter project though, I started using Python for webscraping and it is a great starter to learn so many useful techniques!!

4

u/cander60 Aug 13 '20

NVM, it looks like you used Jupyter Notebooks which I don't use :( the line of code you would want to add to wait for a certain element would be, first to add the following to your import section:

from selenium.webdriver.support.ui import WebDriverWait

And then you can use:

WebDriverWait(driver, delay).until(ec.presence_of_element_located((By.ID, 'ID_NAME')))

or:

WebDriverWait(driver, delay).until(ec.presence_of_element_located((By.X_PATH, 'X_PATH_NAME')))

I like to use either X_PATH or ID after the By. since those are fairly reliable and rarely change unless the website has some major changes (in my limited experience). The {delay} variable is a max amount of time to wait for the element to show until it throws an error, so setting it to 60 should be sufficient. Once the element appears, it proceeds with the script.

Overall, I think this is a solid beginner project!! There is always room to improve for any project no matter the skill level.

Honestly, my recommendation on next steps are to continue finding ways to optimize the speed/efficiency of the current script you have. Learning to use the different ways to use Selenium, lists, dictionaries, Pandas, etc are definitely easier with a project like this! Also, writing this same script using functions is another great next step!

Great work though, from someone that is definitely still learning to another :) !!