Feb-02-2018, 08:22 AM
I am writing a python script for scrapping weather of different city from weather-forecast website. I got an AttributeError in my code and i am unable to gets the cause of error.
Here is my code:
Here is my code:
import urllib.request, urllib.parse, urllib.error
import ssl
import re
# Ignore SSL certificate errors
ctx = ssl.create_default_context()
ctx.check_hostname = False
ctx.verify_mode = ssl.CERT_NONE
condition = 1
braces = '<'
while(condition):
end = 0
start = 0
city = input('enter city: ')
url = "http://www.weather-forecast.com/locations/" + city + "/forecasts/latest"
rawData = urllib.request.urlopen(url, context=ctx).read()
data = rawData.decode()
string = re.search('1 – 3 Day Weather Forecast Summary:</b><span class="read-more-small"><span class="read-more-content"><span class="phrase">', data)
start = string.end()
i = 0
for i in range(start,start+500):
if data[i] == braces:
end = i
break
weather = data[start:end]
final = weather.replace("°C"," °C")
print(final)
print("")This is an error occured:Error:enter city: Mumbai
Traceback (most recent call last):
File "C:\Users\VISHAL\Desktop\wf\weather.py", line 21, in <module>
start = string.end()
AttributeError: 'NoneType' object has no attribute 'end'
