Skip to content

Instantly share code, notes, and snippets.

View erikgregorywebb's full-sized avatar
📈

Erik erikgregorywebb

📈
View GitHub Profile
@erikgregorywebb
erikgregorywebb / Sample Histogram
Last active July 18, 2018 03:22
Sample Histogram
ggplot(moment, aes(x = minuteCount)) +
geom_histogram(binwidth = 10) +
labs(title="Distribution of Minute Counts")
# https://unboxed-analytics.shinyapps.io/the-potential-for-growth/
# http://unboxed-analytics.com/life-hacking/fundamentals-of-investing/
library(FinCal)
library(ggplot2)
library(tidyr)
library(shinythemes)
library(scales)
# Define UI for application that draws a histogram
def getListingContent(listing_link):
# Open the driver
driver = webdriver.Chrome(executable_path="/Users/erikgregorywebb/Downloads/chromedriver 2")
driver.get(listing_link)
# Collect listing informtion
try:
title = driver.find_element_by_css_selector('.listingDetails-title')
location = driver.find_element_by_css_selector('.listingDetails-location')
price = driver.find_element_by_css_selector('.listingDetails-price')
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import time
import pandas as pd
def getListings(url):
links = getListingLinks(url)
listings = []
# Loop over each listing link
for i in range(0, 10):
time.sleep(3)
try:
listing = getListingContent(links[i])
listings.append(listing)
def cleanLlistings(df):
# Split the location variable into location and days_online
df['location'], df['days_online'] = df['location'].str.split('|', 1).str
# Remove the dollar sign in price
df['price'] = df['price'].str.replace('$', '')
df['price'] = df['price'].str.replace(',', '')
# Convert from string to numeric
df['views'] = pd.to_numeric(df['views'])
def main(url):
start_time = time.time()
# Process
raw_df = getListings(url)
df = cleanLlistings(raw_df)
# Export
df.to_csv("/Users/erikgregorywebb/Documents/Python/ksl-scrapper/listings.csv", sep = ',')
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import time
import pandas as pd
def getListingLinks(link):
# Open the driver
driver = webdriver.Chrome(executable_path="/Users/erikgregorywebb/Downloads/chromedriver 2")
driver.get(link)
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.