python script that uses beautifulsoup to write the name, price and url to a .csv on…
- User
python script that uses beautifulsoup to write the name, price and url to a .csv on https://www.customsneakers.ch/collections/alle-sneaker?page=1 from ?page=1 to ?page=5
- Assistant
To achieve this, we will use
requestsandBeautifulSouplibraries, so make sure to install them:pip install requests beautifulsoup4Now, here is a script that writes the name, price, and URL of sneakers to a CSV file:
import csv import requests from bs4 import BeautifulSoup def get_sneaker_data(base_url, page_number): url = f"{base_url}?page={page_number}" response = requests.get(url) soup = BeautifulSoup(response.content, 'html.parser') sneaker_data = [] for product in soup.find_all('div', class_='productgrid--item'): name = product.find('div', class_='product_item--title').text.strip() price = product.find('div', class_='price_item--regular').text.strip() link = product.find('a', class_='productgrid--_imglink')['href'] sneaker_data.append((name, price, link)) return sneaker_data def write_sneaker_data_to_csv(file_name, sneaker_data): with open(file_name, 'a', newline='', encoding='utf-8') as csvfile: writer = csv.writer(csvfile) writer.writerow(['Name', 'Price', 'URL']) for sneaker in sneaker_data: writer.writerow([sneaker[0], sneaker[1], sneaker[2]]) def main(): base_url = 'https://www.customsneakers.ch/collections/alle-sneaker' output_file = 'sneaker.csv' all_sneaker_data = [] for page in range(1, 6): sneaker_data = get_sneaker_data(base_url, page) all_sneaker_data.extend(sneaker_data) write_sneaker_data_to_csv(output_file, all_sneaker_data) if __name__ == '__main__': main() - User
nice, now i have for exampleURL's like https://www.customsneakers.ch/collections/alle-sneaker/products/zurich-airforce-1 so i need to iterate through every URL that is in the .csv and save the Titel, Preis, Beschreibung, URL in a .csv adn the and the pictures that is in a standalone folder names after the Titel
- Assistant
- User
which web scraped data could i sell? make 10 suggestions
- Assistant
While I don't encourage selling web scraped data without explicit consent from the data owner, here are some general suggestions of industries where web scraping could provide valuable data:
- E-commerce: Price monitoring, product availability, and competitor analysis.
- Stock Market: Historical stock prices, market trends, and financial news articles.
- Real Estate: Property listings, rental/sales prices, and housing market trends.
- Job Boards: Job posts, salary information, company reviews, and competitor analysis.
- Travel: Flight and hotel prices, seat availability, customer reviews, and promotions.
- Automotive: Vehicle pricing, feature comparisons, model availability, and customer reviews.
- Consumer Electronics: Product specs, pricing, promotions, customer reviews, and inventory levels.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.