• Subscribe
  • How good is AI at programming? Better than humans?

    Liam Tim
    1 reply
    Here's an example, which chat-gpt 4.0 wrote for me: from selenium import webdriver from selenium.webdriver.chrome.service import Service from selenium.webdriver.common.by import By from selenium.webdriver.chrome.options import Options import csv import time # Set up Selenium WebDriver (adjust the path to your chromedriver) chrome_options = Options() chrome_options.add_argument('--headless') # Run in headless mode service = Service('path/to/chromedriver') # Replace with your path to chromedriver driver = webdriver.Chrome(service=service, options=chrome_options) url = 'https://www.lukiegames.com/snes-super-nintendo-video-games.html' driver.get(url) # Give time for the page to load time.sleep(5) # Find all game entries games = driver.find_elements(By.CSS_SELECTOR, '#searchspring-content > div > div.ss__results.ss__results--grid > article') # Open CSV file for writing with open('video_games.csv', 'w', newline='', encoding='utf-8') as file: writer = csv.writer(file) writer.writerow(['Title', 'Price']) # Iterate through each game entry for game in games: title_elem = game.find_element(By.CSS_SELECTOR, 'p.ss__result__name > a') price_elem = game.find_element(By.CSS_SELECTOR, 'p.ss__result__pricing > span.ss__result__price.ss__result__price--on-sale') title = title_elem.text.strip() if title_elem else 'No title' price = price_elem.text.strip() if price_elem else 'No price' print(f"Title: {title}, Price: {price}") # Debugging output writer.writerow([title, price]) driver.quit() print("Scraping complete. Data saved to video_games.csv") Seems very useful, Here is the result: Title: Tiny Toon Adventures Buster Busts Loose, Price: On Sale: $7.97 Title: Super Scope 6, Price: On Sale: $4.47 Title: Donkey Kong Country 2, Price: On Sale: $22.97 Title: WWF Super Wrestlemania, Price: On Sale: $6.97 Title: Bulls vs. Blazers, Price: On Sale: $5.97 Title: Madden NFL 95, Price: On Sale: $2.47 Title: Taz-Mania, Price: On Sale: $7.97 Title: Super Caesar's Palace, Price: On Sale: $7.47 Title: NHL Stanley Cup, Price: On Sale: $2.97 Title: NFL Quarterback Club, Price: On Sale: $2.97 Title: NBA Live 96, Price: On Sale: $2.97 Title: Chrono Trigger, Price: On Sale: $282.97 Title: Super Mario World, Price: On Sale: $24.97 Title: Super Mario Kart, Price: On Sale: $34.44 Title: Star Fox, Price: On Sale: $13.97 Title: Lethal Enforcers, Price: On Sale: $10.47 Title: WWF Royal Rumble, Price: On Sale: $12.97 Title: Tecmo Super Bowl, Price: On Sale: $10.47 Title: Final Fantasy Mystic Quest, Price: On Sale: $28.47 Title: Super Mario All-Stars, Price: On Sale: $24.47 Title: NFL Football, Price: On Sale: $4.47 Title: Road Runner's Death Valley Rally, Price: On Sale: $7.97 Title: Seaquest DSV, Price: On Sale: $9.97 Title: F1 Pole Position, Price: On Sale: $9.97 Title: Suzuka 8 Hours, Price: On Sale: $6.97 Title: Frank Thomas Big Hurt Baseball, Price: On Sale: $4.97 Title: Mario's Time Machine, Price: On Sale: $12.97 Title: Porky Pig's Haunted Holiday, Price: On Sale: $9.97 Title: Legend of Zelda a Link to the Past, Price: On Sale: $49.97 Title: Paperboy 2, Price: On Sale: $11.97 Title: Mighty Morphin Power Rangers, Price: On Sale: $17.97 Title: Jurassic Park, Price: On Sale: $9.47

    Replies

    Liam Tim
    Here is what I asked AI to do: Write a web scraper using Python and BeautifulSoup. Sample Target: https://www.lukiegames.com/snes-... Rationale: Scrape the video game titles and prices of all the games on the target page. CSS selectors are as follows: 1. Title: #searchspring-content > div > div.ss__results.ss__results--grid > article:nth-child(1) > div > div > p.ss__result__name > a 2. Price: ##searchspring-content > div > div.ss__results.ss__results--grid > article:nth-child(1) > div > div > p.ss__result__pricing > span.ss__result__price.ss__result__price--on-sale Output: Save all the Titles and Prices for all the video games in a CSV file Additional Instructions: Handle character encoding and remove undesirable symbols in the output CSV.