gsc_collect.py 789 B

123456789101112131415161718192021222324252627282930
  1. import traceback
  2. import copy
  3. import operator
  4. import codecs
  5. import sys
  6. import os
  7. import searchconsole
  8. account = searchconsole.authenticate(client_config='c:/keys/service/client_secret.json',credentials='c:/keys/service/credentials.json')
  9. webproperty = account['https://hhh.com.tw/']
  10. #report=webproperty.query.range('2021-01-01', '2020-01-02').dimension('page','query').get()
  11. report=webproperty.query.range('2021-01-01', '2020-05-04').dimension('query').filter('query', '裝修設計', 'contains').get()
  12. total_pos=0
  13. total_count=0
  14. total_clicks=0
  15. for r in report:
  16. print(r)
  17. query=r[0]
  18. clicks=r[1]
  19. impressions=r[2]
  20. ctr=r[3]
  21. position=r[4]
  22. total_clicks+=int(clicks)
  23. total_pos+=float(position)
  24. total_count+=1
  25. print(total_pos/total_count)
  26. print(total_clicks)