I'm setting up a weather data, and I want weather(time, date, Temperature). I didn't found the solution.
from bs4 import BeautifulSoup
import requests
headers = {"User-agent": "Mozilla/5.0 (X11; Linux
x86_64)AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.80
Safari/537.36"}
url = 'https://www.accuweather.com/en/us/new-york-ny/10007/daily-weather-forecast/349727'
page = requests.get(url, headers=headers).text
soup = BeautifulSoup(page, 'html.parser')
weather = soup.find('div', 'five-day').text
time = weather.find('h3')
data = weather.find('h4')
temp = weather.find('div', 'info')
print(time)
print(data)
print(temp)
I have tried to change attribute and curly braces of weather variable name.
weather = soup.find('div', {'class': 'five-day'}).text
time = soup.select_one('div.five-day h3')
Output
During handling of the above exception, another exception occurred: Traceback (most recent call last):
File "first_scraping_solve.py", line 6, in <module> page = requests.get(url, headers=headers).text
File "C:\Users\ABC\AppData\Local\Programs\Python\Python37-32\lib\site packages\requests\api.py", line 75, in get return request('get', url, params=params, **kwargs)
File "C:\Users\ABC\AppData\Local\Programs\Python\Python37-32\lib\site-packages\requests\api.py", line 60, in request return session.request(method=method, url=url, **kwargs)
File "C:\Users\ABC\AppData\Local\Programs\Python\Python37-32\lib\site-packages\requests\sessions.py", line 533, in request resp = self.send(prep, **send_kwargs)
File "C:\Users\ABC\AppData\Local\Programs\Python\Python37-32\lib\site-packages\requests\sessions.py", line 646, in send r = adapter.send(request, **kwargs)
File "C:\Users\ABC\AppData\Local\Programs\Python\Python37-32\lib\site-packages\requests\adapters.py", line 498, in send raise ConnectionError(err, request=request) requests.exceptions.ConnectionError: ('Connection aborted.',
TimeoutError(10060, 'A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond', None, 10060, None))
*I expect the output is Early Am July 21, 27 temperature, partly cloudy