我想知道此文档是否提供用于自动进行URL检查的API? https://developers.google.com/search/apis/indexing-api/v3/prereqs
我已按照该说明进行操作,并将oauth2client(已弃用)更改为Google-oauth2 lib。 我的测试给出了结果:
status code 200
当打印答复时,我收到:
{
"urlNotificationMetadata": {
"url": "https://myexamplesite.com/blogpost1",
"latestUpdate": {
"url": "https://myexamplesite.com/blogpost1",
"type": "URL_UPDATED",
"notifyTime": "2019-07-14T14:25:11.368068597Z"
}
}
}
这是指令中附带的代码:
from oauth2client.service_account import ServiceAccountCredentials
import httplib2
SCOPES = [ "https://www.googleapis.com/auth/indexing" ]
ENDPOINT = "https://indexing.googleapis.com/v3/urlNotifications:publish"
# service_account_file.json is the private key that you created for your service account.
JSON_KEY_FILE = "service_account_file.json"
credentials = ServiceAccountCredentials.from_json_keyfile_name(JSON_KEY_FILE, scopes=SCOPES)
http = credentials.authorize(httplib2.Http())
// Define contents here. This example shows a simple update request. Other types
// of requests are described in the next step.
content = "{
\"url\": \"http://example.com/jobs/42\",
\"type\": \"URL_UPDATED"
}"
response, content = http.request(ENDPOINT, method="POST", body=content)
这是我的尝试:
credentials = service_account.Credentials.from_service_account_info(service_account_info,scopes=SCOPES)
authed_session = AuthorizedSession(credentials)
ENDPOINT = "https://indexing.googleapis.com/v3/urlNotifications:publish"
content = {}
content['url'] = "https://myexamplesite.com/blogpost1"
content['type'] = "URL_UPDATED"
json_ctn = json.dumps(content)
response = authed_session.request('POST',ENDPOINT, data=json_ctn)
print(response.text)
但是在那之后,我检查了该URL,该URL仍未在Google Search Console中建立索引,并且我仍然必须手动进行URL检查,这很无聊!
在此之前,我尝试在python中应用selenium lib来完成这种无聊的任务,但是它仅对某些第一个url有效,然后我遇到了验证码的约束。
是否有用于自动进行URL检查(将新页面编入Google索引)的实用解决方案?