Home > Notes > Web Scrapping and BeautiFul Soup

BeautiFul Soup find()

Web Scrapping and BeautiFul Soup

Python Request_library Explanation
BeautiFul Soup search()
BeautiFul Soup Introduction and Explanation
BeautiFul Soup find_all()
BeautiFul Soup find()
BeautiFul Soup search()

BeautiFul Soup find()

Find () method

The find method is used for finding out the first tag with the specified name or id and returning an object of type bs4.

import requests
 from bs4 import BeautifulSoup
 URL= "https://en.wikipedia.org/wiki/List_of_state_and_union_territo
 page = requests.get(URL)
 soup = BeautifulSoup(page.content,"html")
 #print(soup)
 get_anchoe_value = soup.find("a")
 print(get_anchoe_value)

Beautiful Soup find_all()

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

 # b.) getting reference in anchor tag
 import requests
 from bs4 import BeautifulSoup
 URL= "https://en.wikipedia.org/wiki/List_of_state_and_union_territo
 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"))

Find () method

The find method is used for finding out the first tag with the specified name or id and returning an object of type bs4.

 import requests
 from bs4 import BeautifulSoup
 URL= "https://en.wikipedia.org/wiki/List_of_state_and_union_territo
 page = requests.get(URL)
 soup = BeautifulSoup(page.content,"html")
 #print(soup)
 get_anchoe_value = soup.find("a")
 print(get_anchoe_value)