#!/usr/bin/env python3 """ Craigslist Scanner for Cast Iron Scans Craigslist for cast iron cookware deals """ import requests from datetime import datetime import re from bs4 import BeautifulSoup def search_craigslist_cast_iron(locations=None): """ Search Craigslist for cast iron items locations: list of Craigslist location codes """ if locations is None: locations = [ 'atlanta', 'austin', 'boston', 'charleston', 'chicago', 'dallas', 'denver', 'detroit', 'houston', 'kansascity', 'lasvegas', 'losangeles', 'miami', 'minneapolis', 'nashville', 'newjersey', 'newyork', 'orangecounty', 'philadelphia', 'phoenix', 'pittsburgh', 'portland', 'raleigh', 'sacramento', 'sandiego', 'sfbay', 'seattle', 'stlouis', 'tampa', 'washingtondc' ] items = [] search_query = "cast iron skillet" headers = { 'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36', 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', } # Scan first 10 locations to avoid rate limiting for location in locations[:10]: try: url = f"https://{location}.craigslist.org/search/sss?query={search_query.replace(' ', '%20')}" response = requests.get(url, headers=headers, timeout=10) if response.status_code == 200: soup = BeautifulSoup(response.text, 'html.parser') # Craigslist uses different class names - try multiple selectors results = [] # Try new Craigslist layout results = soup.find_all('li', class_='result-row') # Fallback to old layout if not results: results = soup.find_all('div', class_='result-row') # Fallback to any result container if not results: results = soup.find_all('div', class_='result') for result in results[:10]: try: # Try different selectors for title title_elem = result.find('a', class_='result-title') if not title_elem: title_elem = result.find('a', class_='result-title hdr') if not title_elem: title_elem = result.find('a') if not title_elem: continue title = title_elem.text.strip() link = title_elem.get('href', '') if not link or not title: continue # Extract price price_elem = result.find('span', class_='result-price') price = 0 if price_elem: price_match = re.search(r'\$?([\d,]+)', price_elem.text) if price_match: price = float(price_match.group(1).replace(',', '')) # Extract location loc_elem = result.find('span', class_='result-hood') loc = loc_elem.text.strip() if loc_elem else location # Clean up link if relative if link.startswith('/'): link = f"https://{location}.craigslist.org{link}" items.append({ 'title': title, 'price': price, 'link': link, 'source': f'Craigslist ({location})', 'location': loc, 'found_at': datetime.now().isoformat() }) except Exception as e: continue except Exception as e: print(f"Craigslist {location} error: {e}") return items if __name__ == "__main__": print("🔍 Scanning Craigslist for cast iron...") items = search_craigslist_cast_iron() print(f"Found {len(items)} items") for item in items[:5]: print(f" - {item['title'][:50]} - ${item['price']} ({item['source']})")