개발
구글서치콘솔 Indexing API 사용하여 페이지 색인 대량등록
단마
2023. 3. 18. 09:00
Google Indexing Api를 이용한 구글서치콘솔 색인 등록
Google Cloud Console에서 API키를 먼저 발급 받습니다.
프로젝트를 생성하고 Indexing API를 검색한 후 사용을 누르시면 위와 같이 '관리' 버튼으로 바뀌게 됩니다.
관리 버튼을 누르셔서 인증정보에 API키를 생성하시면 1차 준비는 다 됐습니다.
Python으로 구현하기 위해선 클라이언트 라이브러리인 'google-auth'와 'google-api-python-client'를 우선적으로 설치 합니다.
간단하게 구현된 파이썬 코드
import requests
# Replace YOUR_API_KEY with your Google API key
api_key = "YOUR_API_KEY"
# Replace https://www.example.com with the URL you want to index
url = "https://www.example.com"
# Index the URL
response = requests.get(f"https://indexing.googleapis.com/v3/urlNotifications:publish?key={api_key}",
json={"url": url, "type": "URL_UPDATED"})
# Check the response status code
if response.status_code == 200:
print("URL indexed successfully!")
else:
print(f"Error indexing URL: {response.text}")
구글에서 발급받은 API키를 "YOUR_API_KEY"에 넣고 색인을 요청할 url도 함께 수정하고 실행하면 됩니다.
하루 최대 200개의 페이지 색인요청 제한
저같은 경우 워드프레스 자동 포스팅을 직접 사용중이라 하루에 포스팅 발행을 100건 이상씩 하고 있습니다.
Indexing API를 이용하면 하루 최대 200건의 색인 요청이 가능 합니다. 그래서 위에 코드를 조금 변경하여 사용할 수 있습니다.
파이썬에 pandas 라이브러리를 추가 후 엑셀에서 url 리스트를 읽어서 아래와 같이 처리할 수 있습니다.
엑셀에서 url 200건 읽어서 일괄 처리
import pandas as pd
import requests
# Replace YOUR_API_KEY with your Google API key
api_key = "YOUR_API_KEY"
# Read the URL list from an Excel file
df = pd.read_excel("url_list.xlsx")
url_list = df["URL"].tolist()
# Loop through the URL list and index each URL
for url in url_list:
response = requests.get(f"https://indexing.googleapis.com/v3/urlNotifications:publish?key={api_key}",
json={"url": url, "type": "URL_UPDATED"})
# Check the response status code
if response.status_code == 200:
print(f"{url} indexed successfully!")
else:
print(f"Error indexing {url}: {response.text}")
구글 검색엔진 로봇이 아무리 열심히 색인을 하더라도 우선순위에서 밀리거나 페이지량이 많을때 직접 url을 알려주면 더 빠른 노출 효과를 볼 수 있습니다. 완벽한 소스는 아니지만 활용해 보시면 좋을 것 같습니다.
감사합니다.
반응형