Estou tentando fazer um web scraping, porém se você visualizar o site percebe que certos títulos estão sobre certas colunas. O que meu programa faz é pegar a tabela, criar duas colunas cheias de NaN e atribuir a elas um título de coluna da primeira coluna efetiva do site. O que pode estar errado??? Parece que ele pula 2 colunas, preeenche com os dados e só depois inicia da forma certa.
Preciso que o primeiro titulo va para a terceira coluna, o segundo para a quarta, o terceiro para quinta e assim por diante.
Como fica:
import pandas as pd
import lxml
import html5lib
from bs4 import BeautifulSoup
from pandas import DataFrame
import numpy as np
from selenium import webdriver
from selenium.webdriver.firefox.options import Options
url = "https://www.sunoresearch.com.br/acoes/itsa4/"
option = Options()
option.headless = True
driver = webdriver.Firefox()
driver.get(url)
time.sleep(10)
driver.find_element_by_xpath('//*[@id="demonstratives"]/div[2]/div[1]/div[1]/ng-select/div').click()
driver.find_element_by_xpath('//*[@id="demonstratives"]/div[2]/div[1]/div[1]/ng-select/div/ul/li[2]').click()
driver.find_element_by_xpath('//*[@id="demonstratives"]/div[2]/div[1]/div[2]/ng-select/div').click()
driver.find_element_by_xpath('//*[@id="demonstratives"]/div[2]/div[1]/div[2]/ng-select/div/ul/li[4]').click()
driver.find_element_by_xpath('//*[@id="demonstratives"]/div[2]/div[2]/div/button[2]').click()
element = driver.find_element_by_xpath('//*[@id="demonstratives"]/div[3]/div[2]')
html_content = element.get_attribute('outerHTML')
soup = BeautifulSoup(html_content, 'html.parser')
table = soup.find(name='table')
df_full = pd.read_html(str(table))[0]
pd.set_option('display.max_columns', None)
print(df_full)
driver.quit()