Skip to content

Instantly share code, notes, and snippets.

@jorgejaramillo
Last active January 12, 2022 14:57
Show Gist options
  • Save jorgejaramillo/1287fc1aed352d47342a5656adc58988 to your computer and use it in GitHub Desktop.
Save jorgejaramillo/1287fc1aed352d47342a5656adc58988 to your computer and use it in GitHub Desktop.
Uso solo en Colab
!pip install git+https://github.com/joshcarty/google-searchconsole
# Librerias utilizadas
import searchconsole
import pandas as pd
import numpy as np
from datetime import datetime
from datetime import timedelta
import calendar
# de donde leemos los archivos
from google.colab import drive
drive.mount('/content/drive')
# nos conectamos
try:
account = searchconsole.authenticate(flow="console", client_config='/content/drive/MyDrive/API/test-client_secret_289093706113-7eqp7p21ss4v86ta9ve1gk0g5l27fkm8.apps.googleusercontent.com.json', credentials='/content/drive/MyDrive/API/test-client_secret_289093706113-7eqp7p21ss4v86ta9ve1gk0g5l27fkm8.apps.googleusercontent.com.json')
except:
account = searchconsole.authenticate(flow="console", client_config='/content/drive/MyDrive/API/test-client_secret_289093706113-7eqp7p21ss4v86ta9ve1gk0g5l27fkm8.apps.googleusercontent.com.json', serialize='/content/drive/MyDrive/API/test-client_secret_289093706113-7eqp7p21ss4v86ta9ve1gk0g5l27fkm8.apps.googleusercontent.com.json')
# ver propiedades en GSC
account.webproperties
# seleccionar una propiedad
webproperty = account['https://ejemplo.com/']
# query de la fecha
report = webproperty.query.range('today',days=-120).dimension('page').get().to_dataframe()
report.to_csv(r'reporte.csv', index=False, header=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment