xxxxxxxxxx
Process finished with exit code zero means Process finished without errors
When an error occurs in the code execution a non-zero argument will be the exit code
xxxxxxxxxx
import sys
try:
# Your code here
# If an error occurs, raise an exception or return a specific exit code
# raise Exception("Some error occurred")
# sys.exit(2)
except Exception as e:
# Log the exception or any helpful information
print(f"An error occurred: {e}")
# Optionally, provide more detailed logging with traceback module
# import traceback
# traceback.print_exc()
sys.exit(1) # Use the desired exit code for error condition
else:
sys.exit(0) # Use 0 for successful execution
xxxxxxxxxx
The real program is just outputting hellow as expected. Saying that the Process finished with exit code 0 means that everything worked ok. If an exception occurs in your program or otherwise an exit is generated with non-zero argument, the IDE is gonna inform you about this, which is useful debug information
xxxxxxxxxx
import requests
from bs4 import BeautifulSoup as bs
def get_weather_data(city):
city = city.replace(' ','+')
url = f'https://www.google.com/search?q=weather+of+{city}'
USER_AGENT = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.127 Safari/537.36"
LANGUAGE = "en-US,en;q=0.9"
session = requests.Session()
session.headers['user-agent']= USER_AGENT
session.headers['accept-language'] = LANGUAGE
response = session.get(url)
soup = bs(response.text, 'html.parser')
# Extract Data and Add to Dictionary
results = {}
results[ 'region' ] = soup.find('div', attrs={'id':'wob_loc'}).text
results[ 'daytime' ] = soup.find('div', attrs={'id':'wob_dts'}).text
results[ 'weather' ] = soup.find('span', attrs={'id':'wob_dc'}).text
results[ 'temp' ] = soup.find('span', attrs={'id':'wob_dc'}).text
print(results)
return results
get_weather_data('New York')