Home > Enterprise >  how to filter out certain parts of page when web scraping
how to filter out certain parts of page when web scraping

Time:10-25

I am new to web scraping, and am trying to extract only the 100 fun facts from the following webpage:

css selector

The code:

from urllib.request import urlopen
from bs4 import BeautifulSoup

url = "https://holypython.com/100-python-tips-tricks/"
html = urlopen(url).read()
soup = BeautifulSoup(html, features="html.parser")

titles = soup.select("h3[class='elementor-heading-title elementor-size-default']")

for title in titles:
    print(title.text)

I will leave it as an exercise to you to format the data as you'd like.

  • Related