Answer the question
In order to leave comments, you need to log in
How to write data in Google Spreadsheet on the second sheet?
Good afternoon everyone. I am writing a Python script that parses these two pages:
https://yandex.ru/chat/#/chats/1%2F0%2Fccb05ef5-14...
https://yandex.ru/chat/#/chats/1 %2F0%2F7c6ed1d1-3a...
Namely:
1) the total number of publications
2) the number of reactions to each publication
I want to enter this data into a Google spreadsheet, but not in the first sheet, but in the second. Tell me, how can I specify in the parser that I need to insert this parsed data into the second sheet?
The code:
import gspread
from oauth2client.service_account import ServiceAccountCredentials
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from bs4 import BeautifulSoup
scope = ["https://spreadsheets.google.com/feeds",'https://www.googleapis.com/auth/spreadsheets',"https://www.googleapis.com/auth/drive.file","https://www.googleapis.com/auth/drive"]
creds = ServiceAccountCredentials.from_json_keyfile_name("creds.json", scope)
client = gspread.authorize(creds)
sheet = client.open("test").sheet1 # думал это отвечает за номер листа, написал .sheet2, но такого метода нет.
data = sheet.get_all_records()
list_with_link = ['https://yandex.ru/chat/#/chats/1%2F0%2Fccb05ef5-1472-4e50-a926-602807a6ef94', 'https://yandex.ru/chat/#/chats/1%2F0%2F7c6ed1d1-3a2f-4154-b8e9-1cfee6734076']
...............................
for reac in reaction:
list_with_reac.append(reac)
for text in count_of_publ:
count += 1
for r in list_with_reac:
print('Количество реакций:', r.get_text(strip=True))
sheet.update_cell(2, 2, r.get_text(strip=True))
print('Количество публикаций:', count)
insertCol = [count]
sheet.insert_row(insertCol, 2)
Answer the question
In order to leave comments, you need to log in
For the second
wks = gc.open("doc_name").get_worksheet(1)
For the third
wks = gc.open("doc_name").get_worksheet(2)
etc
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question