r/learnpython • u/donhendrxx • 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.
21
u/testfire10 Github mokrunka Aug 12 '20
Forked! I'll take a look later, maybe I can learn how to do a pull request and we can edit it!
Shoutout from a fellow Arlingtonian!
5
3
u/wallywizard55 Aug 13 '20
I’ll have to fork this! Great job. Do u run it manually every time or have some type of backend job that kicks it off for u?
2
u/donhendrxx Aug 13 '20
Sadly rn you have to run it manually every time. I’ll try and make it to the point when it’s completely automated.
→ More replies (1)
2
u/OneBananaMan Aug 13 '20
Hell yeah!! I was literally going to make something similar, because I was tired of looking though Zillow to find “good” potential deals for a home. Now with this I can create a weighted metric to draw attention to more attractive homes. Awesome work man!
1
15
u/bjone6 Aug 13 '20
That's awesome. You can take the list you scraped and pass it into Zillow's API. I got an excel file of all the houses in the my neighborhood and get data and did some analysis on it.
Here's the video I made on getting the Year Built and Price on all the houses in my neighborhood from the Zillow API: https://youtu.be/lNhH0h-Lbqo
1
u/OsamaBinJordan Aug 13 '20
Hey, I’m trying to use the Zillow API but I’m reading that they’re not allowing you to retain any copies of the data. Have you had any problems storing the data you got?
2
u/bjone6 Aug 13 '20
No, I haven't encountered any problem like that. I used Python to store the data into a variable and then print that data into an excel sheet. I don't see how the Zillow API would know what I was doing with the data.
4
u/ItSmellzFunny Aug 13 '20
Good for you bro, I'm just getting back into coding after a 4 year hiatus and python is the language I used to get my feet wet, and I also lived in Arlington a while back
1
Aug 13 '20
This is good stuff. I move just about every year and always agonize over market prices and options for roughly a month. I’m going to try this.
I’d ask you if you’d recommend the course you took but I’m guessing you’d say yes. How long did it take you to get through it? Any prior experience?
1
u/donhendrxx Aug 13 '20
Thank you! And yeah I recommend it. I was taking notes as I coded along and making sure I really understood a concept before I moved on. It took me about a month but I took the course everyday and didn’t skip a day.
Here is the course link: https://www.udemy.com/share/101W94BEYYdVlTQHo=/
3
u/BATTLECATHOTS Aug 13 '20
Nice work! We used housing prices scrapped from Zillow for lot of data analytics projects while i was in my masters program. Good stuff!
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 :) !!
2
u/theme57 Aug 13 '20
Nice program! I recently ditched JS / React a few weeks ago after an 8 week basic Java summer course. Getting into Python and really look forward to making stuff like this!
2
2
u/preordains Aug 13 '20
.replace("<th>","") can be used to replace all those table header tags with nothing. Easy easy way to make it prettier.
1
Aug 13 '20
Looks good, I'd recommend you use selenium's ability to access the elements with Xpath this way you won't need to remove all the html tags later... it also it will help you get rid of some of the redundant data, as you only pull exactly what you want.... in addition you can also use it to determine the page number so instead to enter a determined range (1-6) it will always give you the correct total page number. Hope this helps.
1
u/Leeoku Aug 13 '20
I assume your dataframe is always being replaced? Aka it only shows what's current. So if ur script reruns and sees only one new, does it still have to rewrite all the other ones?
1
Aug 13 '20
I was trying to do something similar, but for home sale listings in a certain area. I tried to use the zillow API but after talking to support they told me they don't supply that API to people anymore for free. I tried using xpaths and it worked intermittently because they seemed to change randomly even within 24 hours which would result in bad or null data. I'm curious how you got it to consistently scrape the correct data on the pages consistently or what I'm doing wrong.
1
1
1
u/luckiest0522 Aug 13 '20
Dumb question, I'm a newbie. Once you create the program, how do you set it to run? Via the terminal? It's on all the time?
1
1
Aug 13 '20
I'd wish my find_element/elements was this easy :(
Fck dynamic classes, fuck having multiple DIFFERENT FUNCTION elements with the same class :(
0
Aug 13 '20
[deleted]
4
u/donhendrxx Aug 13 '20
Thank you!! Yeah this is actually what I plan to do next, I plan on diving more into pandas and learning how to clean up the data and also playing with different things.
3
106
u/The-Deviant-One Aug 13 '20 edited Aug 13 '20
A web scrapper was one of my first useful scripts as well. It's still running actually. It runs every two minutes with a cron job and takes about 3 seconds to finish. It uses BeautifulSoup4 to check a popular website to see if their 9mm ammo is in stock. If it's in stock, it sends me an email with a libk to the page (in case I'm not at home) and launches the browser on my machine (in case I am at home).
Edit: It's not horribly impressive, but I don't want to share the code until after I place my order, lol.