https://developers.google.com/webmaster-tools/search-console-api-original/v3/searchanalytics/query
Google Analytics(分析)告诉我,从Google搜索中访问了大约20,000页,但谷歌搜索控制台API返回的网页不到5万。更改startRow
无济于事。
我将谷歌搜索控制台与谷歌分析联系起来真是奇怪,当在GA(收购 - >搜索控制台 - >登陆页面)中查看GSC数据时,那里的GSC数据也为我提供了大约20k行。 / p>
如何从Google Search Console API中获取所有~20k行?
date_str = '2017-12-20'
start_index = 0
row_limit = 5000
next_index = 5000
rows = []
while next_index == row_limit:
req = webmasters_service.searchanalytics().query(
siteUrl='https://tenor.com/',
fields='responseAggregationType,rows',
body={
"startDate": date_str,
"endDate": date_str,
"searchType": search_type,
"dimensions": [
"page",
],
"rowLimit": row_limit,
"startRow": start_index,
},
)
try:
resp = req.execute()
next_rows = resp['rows']
rows += next_rows
next_index = len(next_rows)
start_index += next_index
except Exception as e:
print(e)
break
return rows