benchmarks.wiki / Public workspace

BigCodeBench / BigCodeBench v0.1.0_hf dd9ad034-1dbe-5b99-9c6a-1636793a568d

Problem

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

complete prompt

import ast
import requests
from bs4 import BeautifulSoup


def task_func(url):
    """
    Fetches the content of a webpage specified by its URL, parses it to find <script> tags,
    and attempts to evaluate any string within these tags as a Python dictionary.

    Parameters:
    - url (str): The URL of the webpage to scrape.

    Returns:
    - list of dict: A list containing dictionaries that were successfully evaluated from string representations
      found within <script> tags on the webpage. 
    
    Note:
    - If an error occurs during the request or if no dictionaries are found/evaluable, an empty list is returned.

    Requirements:
    - ast
    - requests
    - bs4.BeautifulSoup

    Example:
    >>> task_func('https://example.com')
    [{'key': 'value'}, ...]
    """

instruct prompt

Fetches the content of a webpage specified by its URL, parses it to find <script> tags, and attempts to evaluate any string within these tags as a Python dictionary.
Note that: If an error occurs during the request or if no dictionaries are found/evaluable, an empty list is returned.
The function should output with:
    list of dict: A list containing dictionaries that were successfully evaluated from string representations
    found within <script> tags on the webpage.
You should write self-contained code starting with:

Code

import ast
import requests
from bs4 import BeautifulSoup
def task_func(url):

code prompt

Code

import ast
import requests
from bs4 import BeautifulSoup
def task_func(url):

entry point

task_func

libs

  • ast
  • 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