Python为每个单元格编写一个字符

Python为每个单元格编写一个字符,python,web-scraping,google-sheets,Python,Web Scraping,Google Sheets,我正在为我的工作创建一个网站,基本上需要搜索一个名为“cpf”(存储在谷歌表单中)的数字列表,然后写下url将显示的信息,但现在我在表单更新方面遇到了一些问题 我给我每个细胞一个字符,你知道为什么会这样吗 class CpfSearch(object): def __init__(self, spreadsheet_name): self.cpf_col = 1 self.nome_col = 2 self.idade_col = 3 self.beneficio

我正在为我的工作创建一个网站,基本上需要搜索一个名为“cpf”(存储在谷歌表单中)的数字列表,然后写下url将显示的信息,但现在我在表单更新方面遇到了一些问题

我给我每个细胞一个字符,你知道为什么会这样吗

class CpfSearch(object):
def __init__(self, spreadsheet_name):
    self.cpf_col = 1
    self.nome_col = 2
    self.idade_col = 3
    self.beneficio_col = 4
    self.concessao_col = 5
    self.salario_col = 6
    self.consig_col = 9
    self.card_col = 15

    scope = ['https://www.googleapis.com/auth/spreadsheets',
             'https://www.googleapis.com/auth/drive.readonly']

    creds = ServiceAccountCredentials.from_json_keyfile_name('CONSULTAS.json', scope)

    client = gspread.authorize(creds)

    self.sheet = client.open(spreadsheet_name).sheet1

def process_cpf_list(self):
    cpfs = self.sheet.col_values(self.cpf_col)[1:]

    bot_url = BOT(cpfs)
    nomes, idades, beneficios, concessoes, salarios, consigs, cards = bot_url.search_cpfs()

    print("Atualizando...")
    for i in range(len(nomes)):
        self.sheet.update_cell(i+2, self.nome_col, nomes[i])
        self.sheet.update_cell(i+2, self.idade_col, idades[i])
        self.sheet.update_cell(i+2, self.beneficio_col, beneficios[i])
        self.sheet.update_cell(i+2, self.concessao_col, concessoes[i])
        self.sheet.update_cell(i+2, self.salario_col, salarios[i])
        self.sheet.update_cell(i+2, self.consig_col, consigs[i])
        self.sheet.update_cell(i+2, self.card_col, cards[i])


cpf_updater = CpfSearch('TESTE')
cpf_updater.process_cpf_list()
这是搜索结果


发布此答案以使其他可能面临此问题的人更清楚。 如前所述:

在search_cpfs()中,返回字符串nome、idade、bengiio、concessao、salario、consig、card。试着返回列表名称,idades,bengiios,concessoes,salarios,consigs,cards


如果你打印(nomes,idades,bengiios,concessos,salarios,consigs,cards)`它会确认这一点还是不会谢谢你的关注Dan,我已经在search_cpfs()中发布了search_cpfs()了你正在返回字符串nome,idade,bengiio,concessao,salario,考虑一下,卡。试着把名字,idades,bengiios,concessoes,salarios,consigs,cards都还给我。谢谢,伙计,这就像一个符咒!来自巴西的拥抱
    def search_cpfs(self):
    nomes = []
    idades = []
    beneficios = []
    concessoes = []
    salarios = []
    bancoss = []
    bancoscard = []
    consigs = []
    cards = []

    for cpf in self.cpfs:
        print(f"Procurando {cpf}.")

        self.driver.get(self.bot_url)

        cpf_input = self.driver.find_element_by_xpath('//*[@id="search"]/div/div[1]/input')
        cpf_input.send_keys(cpf)

        time.sleep(2)

        cpfButton = self.driver.find_element_by_xpath('//*[@id="search"]/div/div[2]/button')
        cpfButton.click()

        time.sleep(2)

        nome = self.driver.find_element_by_xpath("/html/body/main[1]/div[1]/div[1]/div[1]/div[1]/h2").text
        idade = self.driver.find_element_by_xpath("/html/body/main[1]/div[1]/div[1]/div[1]/div[1]/ul/li[2]").text
        beneficio = self.driver.find_element_by_xpath("/html/body/main[1]/div[1]/div[1]/div[1]/div[2]/div[5]/span/b").text
        concessao = self.driver.find_element_by_xpath("/html/body/main[1]/div[1]/div[1]/div[1]/div[2]/div[2]/span").text
        salario = self.driver.find_element_by_xpath("/html/body/main[1]/div[1]/div[2]/div/div[3]/div[1]/div[1]/span").text
        consig = self.driver.find_element_by_xpath("/html/body/main[1]/div[1]/div[1]/div[3]/div[2]/span").text
        card = self.driver.find_element_by_xpath("/html/body/main[1]/div[1]/div[1]/div[3]/div[3]/span").text

        nomes.append(nome)
        idades.append(idade)
        beneficios.append(beneficio)
        concessoes.append(concessao)
        salarios.append(salario)
        consigs.append(consig)
        cards.append(card)

        print(nome, idade, beneficio, concessao, salario, consig, card)

    return nome, idade, beneficio, concessao, salario, consig, card