benchmarks.wiki / Public workspace

BigCodeBench / BigCodeBench v0.1.0_hf 19bac3cf-b05f-54ab-9801-da4156c9e839

Problem

Answer published by the source. Consult the official source to check your work against its answer.

complete prompt

import bs4
import requests
import re
import csv

def task_func(url="http://example.com", csv_path="emails.csv", 
          regex=r"\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]{2,7}\b", 
          headers={'User-Agent': 'Mozilla/5.0'}):
    """
    Scrapes a web page to extract all email addresses using a specified regular expression pattern and writes them to a CSV file. The csv file is
    always created eventhough no email is found in the url. The header of the csv should be "Emails".

    Parameters:
    - url (str): The URL of the web page to scrape. Default is "http://example.com".
    - csv_path (str): The filesystem path where the CSV file should be saved. Default is "emails.csv".
    - regex (str): The regular expression pattern used to identify email addresses. Default is a pattern that matches common email formats.
    - headers (dict): The HTTP headers to use for the request. Default includes a User-Agent header.

    Returns:
    - str: The path to the CSV file where the extracted email addresses have been saved.

    Requirements:
    - bs4
    - requests
    - re
    - csv
    
    Examples:
    >>> task_func()
    'emails.csv'
    >>> task_func(url="http://another-example.com", csv_path="another_emails.csv")
    'another_emails.csv'
    """

instruct prompt

Scrapes a web page to extract all email addresses using a specified regular expression pattern and writes them to a CSV file. The csv file is always created eventhough no email is found in the url. The header of the csv should be "Emails".
The function should output with:
    str: The path to the CSV file where the extracted email addresses have been saved.
You should write self-contained code starting with:

Code

import bs4
import requests
import re
import csv
def task_func(url="http://example.com", csv_path="emails.csv", 
          regex=r"\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]{2,7}\b", 
          headers={'User-Agent': 'Mozilla/5.0'}):

code prompt

Code

import bs4
import requests
import re
import csv
def task_func(url="http://example.com", csv_path="emails.csv", 
          regex=r"\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]{2,7}\b", 
          headers={'User-Agent': 'Mozilla/5.0'}):

entry point

task_func

libs

  • csv
  • re
  • bs4
  • requests

Discussion

Discussion

No discussion posts on this page yet. Share a minimal failing example, an algorithm with its complexity, or a reproducible command and result. Use the posting template.

See answer Answer published by the source

Artifacts

Code, notes and reproducible work shared by participants. Files are served from a separate origin.

No artifacts on this page yet. Share reproducible code or notes in a contribution. Share a minimal failing example, an algorithm with its complexity, or a reproducible command and result. Use the posting template.

Source and history

Official source

initial import