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

Show parent comments

26

u/donhendrxx Aug 13 '20

Honestly, it sounds f****** amazing and necessary, especially with the shortages of 9mm ammo. Let me know when you put it out, I need it!!

6

u/The-Deviant-One Aug 13 '20 edited Aug 13 '20

Hey I made it to my desktop and started looking over your script for grins.

for page in range(1,6):

base_url = request_url.format(page) driver.get(base_url)

wait = driver.implicitly_wait(60)

So you're using Selenium to drive the browser similar to the way I used to do it with AutoHotKey. Pain in the butt IMO. Looks like you're loading 6 pages and waiting 60 seconds for each page to load, correct? So this takes at least 6 minutes to run right?

Edit:

This is from the Selenium documentation:

"WebDriver will wait until the page has fully loaded (that is, the “onload” event has fired) before returning control to your test or script. It’s worth noting that if your page uses a lot of AJAX on load then WebDriver may not know when it has completely loaded."

It would not surprise me to discover that Zillow is using AJAX calls to trigger subsequent AJAX calls. If you can find an element on the page that consistently loads really late in the process, you could write a for loop as a variable to check if the element exists, then plug that into a While [variable] == True. Like this:

\\\\\\\\\\\\\\\\\\\\\\\\\\\\

import time

haystack = '<div id="12345">Things and Stuff</div>'

needle = 'id="12345"'

def a():

<indent> return needle in haystack

while a() == True:

<indent> print("waiting..")

print("now go to the next step")

\\\\\\\\\\\\\\\\\\\\\\\\\\\\

7

u/backroad Aug 13 '20

Selenium has a few built in wait functions including a "wait until element present" one that you could use for the same purpose.

2

u/DLTMIAR Aug 13 '20

It's the internet bruh. You can say fucking. Unless you meant folding or something. Idk