Skip to content

Instantly share code, notes, and snippets.

@palumbo
Created October 7, 2020 16:05
Show Gist options
  • Save palumbo/a08c5c3f745594bd0d73324c321e34dd to your computer and use it in GitHub Desktop.
Save palumbo/a08c5c3f745594bd0d73324c321e34dd to your computer and use it in GitHub Desktop.
import sys
import requests
import os
from urllib.request import urlopen
from bs4 import BeautifulSoup
# unpack argv
script, url = sys.argv
# get URL
r = requests.get(url)
# check for <Response 200>
""" if str(r) != '<Response [200]>':
print("Problem: ", r)
else:
print("Connection Successful - Received <Response [200]>") """
# parse content through BeautifulSoup
soup = BeautifulSoup(r.content, 'lxml')
# scrape class_="bidsold" from search page
prices = []
for price in soup.find_all("span", class_="bold bidsold"):
# print(type(price.text), price.text)
if "Trending at" not in price.text:
if "to" not in price.text:
clean_price = price.text.strip()
prices.append(clean_price)
print(clean_price)
# determine average sold price of item
avg_price = []
for p in prices:
fprice = float(p.strip( '$' ))
avg_price.append(fprice)
average_price = sum(avg_price) / len(avg_price)
print( "The average price is ", round(average_price, 2))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment