Speed up development with full-stack environments for every branch.

Learn More

Beautiful Soup Tutorial [Python]

Forked from Basic Python.

86 Runs 167 Views 77 Copies


GoTrained 1

published 4 months ago

    from bs4 import BeautifulSoup
    import requests
    url = "http://www.htmlandcssbook.com/code-samples/chapter-04/example.html"
    # Getting the webpage, creating a Response object.
    response = requests.get(url)
    # Extracting the source code of the page.
    data = response.text
    # Passing the source code to Beautiful Soup to create a BeautifulSoup object for it.
    soup = BeautifulSoup(data, 'lxml')
    # Extracting all the <a> tags into a list.
    tags = soup.find_all('a')
    # Extracting URLs from the attribute href in the <a> tags.
    for tag in tags:
    Please login/signup to get access to the terminal.

    Your session has timed out.

    Dismiss (the page may not function properly).