BeautiFul Soup find_all()

Estimated reading: 1 minute 352 views

Beautiful Soup find_all()

find_all is used for returning all the matches after scanning the entire document.

				
					# a.) getting all anchor tag

import requests
from bs4 import BeautifulSoup
URL= "https://en.wikipedia.org/wiki/List_of_state_and_union_territory_capitals_in_India"
page = requests.get(URL)
soup = BeautifulSoup(page.content,"html")
#print(soup)
get_all_anchor_value = soup.find_all("a")
for i in get_all_anchor_value:
  print(i)
				
			
				
					  
# b.) getting reference in anchor tag

import requests
from bs4 import BeautifulSoup
URL= "https://en.wikipedia.org/wiki/List_of_state_and_union_territory_capitals_in_India"
page = requests.get(URL)
soup = BeautifulSoup(page.content,"html")
#print(soup)
get_all_anchor_value = soup.find_all("a")
for i in get_all_anchor_value:
  print(i.get("href")) 
				
			

Leave a Comment

CONTENTS