Answers for "beautiful soup code"

8

use beautifulsoup

#start


from bs4 import BeautifulSoup
import requests

req = requests.get('https://www.slickcharts.com/sp500')
soup = BeautifulSoup(req.text, 'html.parser')
Posted by: Guest on April-30-2020
0

beatiful_soup_code

# To run this, download the BeautifulSoup zip file
# http://www.py4e.com/code3/bs4.zip
# and unzip it in the same directory as this file

from urllib.request import urlopen
from bs4 import BeautifulSoup
import ssl

# Ignore SSL certificate errors
ctx = ssl.create_default_context()
ctx.check_hostname = False
ctx.verify_mode = ssl.CERT_NONE

url = input('Enter - ')
html = urlopen(url, context=ctx).read()
soup = BeautifulSoup(html, "html.parser")

# Retrieve all of the anchor tags
tags = soup('a')
for tag in tags:
    # Look at the parts of a tag
    print('TAG:', tag)
    print('URL:', tag.get('href', None))
    print('Contents:', tag.contents[0])
    print('Attrs:', tag.attrs)
Posted by: Guest on July-12-2021

Code answers related to "Shell/Bash"

Browse Popular Code Answers by Language