Home > Enterprise >  Beautifulsoup and selenium returning none value when I use soup.find()
Beautifulsoup and selenium returning none value when I use soup.find()

Time:03-29

I have been digging on the site for some time and im unable to find the solution to my issue. Im fairly new to web scraping and trying to simply extract some values from a web page using beautiful soup and selenium.

from bs4 import BeautifulSoup
from selenium import webdriver
import requests
import time

PATH = "C:\Program Files (x86)\chromedriver.exe"

url = "https://meteofrance.com/previsions-meteo-france/nanterre/92000"

driver = webdriver.Chrome(PATH)
driver.get(url)
time.sleep(3)
page = driver.page_source
driver.quit()
soup = BeautifulSoup(page, 'html.parser')
temp = soup.find('strong', class_="temp")
info = soup.find('p', class_="svg_container")
wind = soup.find('strong', class_="wind-speed")
print(temp.text)
print(info)
print(wind)

At the most basic level, all im trying to do is access a specific tag within the website.

For the temp it work but for info and wind I get none and I have the same problem with a other website. I think the problem is I don t get the full HTML but I can t find a solution for this. The only solution I find is use selenium but my problem stay the same.

I hope someone can help me !

Thanks Zway

from bs4 import BeautifulSoup
from selenium import webdriver
import requests
import time

PATH = "C:\Program Files (x86)\chromedriver.exe"

url = "https://meteofrance.com/previsions-meteo-france/nanterre/92000"

driver = webdriver.Chrome(PATH)
driver.get(url)
time.sleep(3)
page = driver.page_source
driver.quit()
soup = BeautifulSoup(page, 'html.parser')
temp = soup.find('strong', class_="temp")
info = soup.find('p', class_="svg_container")
wind = soup.find('strong', class_="wind-speed")
print(temp.text)
print(info)
print(wind)

This is what I get when I execute

17° None None

CodePudding user response:

You are near to your goal - Just select your elements more specific to get your information:

...
temp = soup.find('strong', class_="temp")
info = soup.find('div', class_="svg_container").img['title']
wind = soup.find('p', class_="wind-speed").text.strip()
print(temp.text)
print(info)
print(wind)
...

Output:

18°
Très nuageux
10
  • Related