I am currently building a web scraper for Real Estate data. I'm working in Python and I've come across an error I can't seem to be able to fix.
for i in range(len(s)):
if '$' in s[i]:
price.append(s[i])
elif 'bath' in s[i]:
left = s[i].partition(",")[0]
right = s[i].partition(",")[2]
bed_bath.append(left)
sqft_lot.append(right)
elif 'fort collins' in s[i].lower():
address0 = s[i-1]+' '+s[i]
address.append(address0)
elif s[i].lower() == 'advertisement':
del s[i]
else:
continue
Value of 's' being:
display = Display(visible=0, size=(800, 600))
display.start()
browser = webdriver.Firefox()
browser.get(realtor.format(format))
p = browser.find_element(By.XPATH, "//ul[@class='jsx-343105667 property-list list-unstyle']")
content = p.text
s = re.split('\n',content)
This is basically supposed to iterate through the array s, and add them to a separate array [price,bed_bath,sqrft_lot,address] to be used in a DataFrame. I know that it is indexing properly, I've printed each line consecutively using for i in range(len(s)): print s[i], which works, but then when I try to implement logic it's just breaking.
Getting error:
if '$' in s[i]:
**IndexError: list index out of range**
Any input into why this is happening would be much appreciated.
swhich didn't work for you?del s[i]. Surely this affects the length ofsand might mean that you runioff the end.sas a python list, and not a code generating one, as we can't run that code.