Skip to content Skip to sidebar Skip to footer

Beautifulsoup Find Class Return None

I am using BeautifulSoup and python writing code to scraping information from website, after I try to get particular content by 'class' category, it return '[ ]', is this means 'no

Solution 1:

The issue is page content are not loaded while you are trying to scrape,

You can use selenium with BeautifulSoup

Example

import time
from bs4 import BeautifulSoup
from selenium import webdriver

url = "https://www.metservice.com/towns-cities/locations/auckland/7-days"
browser = webdriver.Firefox()
browser.get(url)
time.sleep(5)
html = browser.page_source
soup = BeautifulSoup(html, 'html.parser')
week = soup.find_all(class_='IconWithText-content')
print(week)

Solution 2:

If you look at the actual html returned by that request, you'll find there's no element with class of IconWithText-content in there, so you won't find it.

What you did would work, or this:

soup.find_all(attrs={'class': 'IconWithText-content'})

Post a Comment for "Beautifulsoup Find Class Return None"