Issue
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
Solution
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
Answered By - HedgeHog
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.