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

Learn More

Beautiful Soup Tutorial [Python]

Forked from Basic Python.

73 Runs 109 Views 59 Copies
Saved

Saved

GoTrained 1

GoTrained
published a month 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:
        print(tag.get('href'))
    
    Please login/signup to get access to the terminal.

    Your session has timed out.

    Dismiss (the page may not function properly).