I am brand new to python and coding in general. Can anyone understand why I am getting this IndexError?
Traceback (most recent call last):
File "\\Mac\Home\Desktop\Python\Lab1\lab1_querystring.pageresults.addresssplit.headersadded.columnsadded.keysaddedtodictionary.py", line 54, in <module>
city = splitaddress[1]
IndexError: list index out of range
The list I am trying to pull in each of my if statements/suites from has four items, but for some reason it keeps telling me the list index is out of range.
for listing in splititems:
name = parse(listing,"itemprop=\"name\">","<").strip() # extract the business name
# Try to extract the address into its constituent parts - street address, city, postal, see if you can put them into different columns in excel
address = parse(listing,"<div class=\"ltext\" itemprop=\"address\" itemscope itemtype=\"http://schema.org/PostalAddress\">","</div>").strip() # extract the address
splitaddress = address.split(',')
streetaddress = splitaddress[0]
city = splitaddress[1]
postalcode = splitaddress[2]
if len(splitaddress) >= 0:
print splitaddress[0]
if len(splitaddress) >= 1:
print splitaddress[1]
if len(splitaddress) >= 2:
print splitaddress[2]
phone = parse(listing,"itemprop=\"telephone\" content=\"","\"/>").strip() # extract the phone number
print name, address, phone # take this out when you're finished your script - this is just for testing
resultlist.append({'businessname':name,'streetaddress':streetaddress, 'city':city, 'postalcode':postalcode, 'phone':phone})
del name,streetaddress,city,postalcode,phone