Using Selectors in Beautiful Soup to Scrape Using Classes & IDs

Python

Here we use a Beautiful Soup selector to get all the tags in a webpage with that uses the css class "links" and also the tag in the webpage with the css id "main_header".

 1|  import requests
 2|  from bs4 import BeautifulSoup
 3|  
 4|  response = requests.get('https://en.wikipedia.org/wiki/FTSE_100_Index')
 5|  parser = BeautifulSoup(response.content, 'html.parser')
 6|  
 7|  links = parser.select(".links")
 8|  
 9|  main_header = parser.select("#main_header")
Did you find this snippet useful?

Sign up for free to to add this to your code library