我创建了一个机器人,该机器人可以访问correios网站并获取巴西所有县和州的所有代理商的所有信息,但是我基本上犯了一个错误:当出现与AC代理商不同的类型时,代码开始打印很多重复的信息,我该怎么办?这是我的代码中按县列出机构的部分:
info_list = driver.find_elements_by_xpath("//table[@class = 'dadosAgencia']//span")
td_list = driver.find_elements_by_xpath("//table[@class = 'dadosAgencia']//td")
get_table_list = driver.find_elements_by_xpath("//table[@class = 'dadosAgencia']")
for data in range(0,len(get_table_list)):
time.sleep(0.8)
for record in range(0,len(td_list)):
text_info = td_list[record].get_attribute('innerText')
#if text_info == 'Endereço: ' in lista_valores:
# pass
#else:
lista_valores.append(text_info)
lista_valores = [record.replace('\n', '') for record in lista_valores]
lista_valores = [record.replace('\t', '') for record in lista_valores]
print(text_info)
#print(text_info)
lista_valores = [';'.join(lista_valores)]
#lista_valores = [for record in lista_valores.split()]
x = pd.DataFrame(lista_valores)
x.to_csv(file,encoding = 'utf-8-sig')
del lista_valores[:]