You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
frombs4importBeautifulSoupimporturllib.requestpage=urllib.request.urlopen("https://google.com/").read()
soup=BeautifulSoup(page, 'html.parser') # Uses html.parser to parse the page
Working with Elements
# Get All Elements inside the pagepageElementsAll=soup.findAll()
# Get Only Body Elements inside the pagepageElementsBody=soup.findAll("body")
# Get only Paragraph ElementspageElementsBody=soup.findAll("p")
# Get Div Element By Idelem=soup.find("div", {"id": "articlebody"})
# Get Div Element By Classelem=soup.find("div", {"class": "articlebody"})
Extract Data inside Elements
# Get Attributeselem[0].attrs# Get Tag Nameelem[0].name