목차
다양한 보안 조치(reCAPTCHA, 동적 콘텐츠, IP 확인 등)로 인해, 해당 분야에 경험이 있더라도 순수 파이썬으로 구글 지도를 스크래핑하는 것은 쉽지 않습니다. 다행히도 파이썬이나 다른 프로그래밍 언어를 사용하여 리뷰를 스크래핑할 수 있는 도구가 많이 있습니다.
이 글에서는 구글 맵 데이터를 스크래핑하는 데 가장 널리 사용되는 두 가지 도구, 즉 브라우저 에뮬레이션과 Outscraper API를 살펴보겠습니다. 이 튜토리얼만으로도 개인 사용자는 물론 빅데이터 팀까지 데이터를 추출하는 데 충분할 것입니다.
파이썬으로 Google Places 데이터 추출하기
순수 파이썬으로 구글을 크롤링해 볼 수는 있지만, 10회 정도의 요청을 보내면 소프트웨어가 차단되는 것을 확인할 수 있을 것입니다. 이는 구글이 세션을 검증하고, 백그라운드에서 자바스크립트를 통해 API 호출이 이루어지기를 기대하기 때문입니다. 따라서 구글 맵스가 크롤러를 차단하지 않도록 하려면 브라우저 에뮬레이션이 필요합니다. 또한 프록시를 사용할 수도 있습니다.
브라우저 에뮬레이션을 사용하여 구글 지도 스크레이퍼를 만들기 시작하려면, 이 튜토리얼에 설명된 단계를 따라 주세요. 파이썬과 셀레니움을 사용하여 구글 지도를 스크래핑하는 방법.
파이썬으로 6분 만에 구글 플레이스 데이터 수집하기
Google Maps 스크레이퍼를 개발하고 유지 관리하는 데는 상당한 시간과 노력이 필요할 수 있습니다. 따라서 많은 엔지니어링 팀은 본연의 업무에 집중하고, 앱에 필요한 신뢰할 수 있는 데이터 소스로 Outscraper 플랫폼을 활용하는 것이 유리하다고 생각합니다.
SDK를 사용하여 구글 지도 데이터 추출하기
1. Python 3 이상이 필요하며, 이 파이썬 패키지. 다음 명령어를 실행하여 패키지를 설치하십시오.
pip install google-services-api
2. 다음에서 API 키를 받으세요. 프로필 페이지.
3. 패키지를 가져온 다음 키를 사용하여 초기화합니다. 다음과 같이 검색을 실행할 쿼리를 지정합니다. “미국 로스앤젤레스 인근의 식당.” 각 쿼리 내에 국가와 도시를 포함시키세요.
from outscraper import ApiClient
api_cliet = ApiClient(api_key='KEY_FROM_OUTSCRAPER')
response = api_cliet.google_maps_search(
'Restaurants near Los Angeles, USA',
language='en',
region='es',
limit=100
)
4. 데이터가 불러오기까지 몇 초간 기다리세요.
[
{
"name": "Sushi Gen",
"full_address": "422 E 2nd St, Los Angeles, CA 90012",
"borough": "Little Tokyo",
"street": "422 E 2nd St",
"city": "Los Angeles",
"postal_code": "90012",
"country_code": "US",
"country": "United States of America",
"us_state": "California",
"state": "California",
"plus_code": null,
"latitude": 34.0466917,
"longitude": -118.2385444,
"time_zone": "America/Los_Angeles",
"site": "http://www.sushigen-dtla.com/",
"phone": "+1 213-617-0552",
"type": "Sushi restaurant",
"subtypes": "Sushi restaurant, Japanese restaurant",
"posts": null,
"rating": 4.6,
"reviews": 1244,
"reviews_data": null,
"photos_count": 1261,
"google_id": "0x80c2c63850150b9d:0x96cdcf9a38a24170",
"place_id": "ChIJnQsVUDjGwoARcEGiOJrPzZY",
"reviews_link": "https://search.google.com/local/reviews?placeid=ChIJnQsVUDjGwoARcEGiOJrPzZY&q=Restaurants+near+Los+Angeles,+USA&authuser=0&hl=en&gl=US",
"reviews_id": "-7580174336512605840",
"photo": "https://lh5.googleusercontent.com/p/AF1QipMtt0bMtJTF1bDTZ2tbXuWXtZTNWmvjJUu3ejKy",
"working_hours_old_format": "Monday: Closed | Tuesday: 11AM\u20132PM,5\u20137:30PM | Wednesday: 11AM\u20132PM,5\u20137:30PM | Thursday: 11AM\u20132PM,5\u20137:30PM | Friday: 11AM\u20132PM,5\u20138PM | Saturday: 4\u20138PM | Sunday: Closed",
"working_hours": {
"Monday": "Closed",
"Tuesday": "11AM\u20132PM,5\u20137:30PM",
"Wednesday": "11AM\u20132PM,5\u20137:30PM",
"Thursday": "11AM\u20132PM,5\u20137:30PM",
"Friday": "11AM\u20132PM,5\u20138PM",
"Saturday": "4\u20138PM",
"Sunday": "Closed"
},
"business_status": "OPERATIONAL",
"about": {
"Service options": {
"Takeout": true,
"Delivery": false
},
"Health & safety": {
"Mask required": true
},
"Highlights": {
"Great tea selection": true
},
"Popular for": {
"Lunch": true,
"Dinner": true,
"Solo dining": true
},
"Accessibility": {
"Wheelchair accessible entrance": true
},
"Offerings": {
"Healthy options": true,
"Small plates": true
},
"Dining options": {
"Dessert": true
},
"Amenities": {
"High chairs": true
},
"Atmosphere": {
"Casual": true,
"Cozy": true
},
"Crowd": {
"Groups": true,
"Tourists": true
},
"Planning": {
"Dinner reservations recommended": true,
"Accepts reservations": true,
"Usually a wait": true
}
},
"range": "$$$",
"reviews_per_score": {
"1": 25,
"2": 14,
"3": 52,
"4": 291,
"5": 862
},
"reserving_table_link": null,
"booking_appointment_link": null,
"owner_id": "100930306416993024046",
"verified": true,
"owner_title": "Sushi Gen",
"owner_link": "https://www.google.com/maps/contrib/100930306416993024046",
"location_link": "https://www.google.com/maps/place/Sushi+Gen/@34.0466917,-118.2385444,14z/data=!4m8!1m2!2m1!1sSushi+Gen!3m4!1s0x80c2c63850150b9d:0x96cdcf9a38a24170!8m2!3d34.0466917!4d-118.2385444"
},
{
"name": "Water Grill",
"full_address": "544 S Grand Ave, Los Angeles, CA 90071",
"borough": "Financial District",
"street": "544 S Grand Ave",
"city": "Los Angeles",
"postal_code": "90071",
"country_code": "US",
"country": "United States of America",
"us_state": "California",
"state": "California",
"plus_code": null,
"latitude": 34.0490403,
"longitude": -118.25470659999999,
"time_zone": "America/Los_Angeles",
"site": "https://www.watergrill.com/la",
"phone": "+1 213-891-0900",
"type": "Seafood restaurant",
"subtypes": "Seafood restaurant",
"posts": null,
"rating": 4.4,
"reviews": 1387,
"reviews_data": null,
"photos_count": 1429,
"google_id": "0x80c2c7b4901ce7c7:0x2ad996c9a82b097c",
"place_id": "ChIJx-cckLTHwoARfAkrqMmW2So",
"reviews_link": "https://search.google.com/local/reviews?placeid=ChIJx-cckLTHwoARfAkrqMmW2So&q=Restaurants+near+Los+Angeles,+USA&authuser=0&hl=en&gl=US",
"reviews_id": "3087664812393171324",
"photo": "https://lh5.googleusercontent.com/p/AF1QipPX7-DP07mvQQSxDjDjuOVYj9HlQ2bvNJ_EEZYW",
"working_hours_old_format": "Monday: 11:30AM\u20139PM | Tuesday: 11:30AM\u20139PM | Wednesday: 11:30AM\u20139PM | Thursday: 11:30AM\u20139PM | Friday: 11:30AM\u201310PM | Saturday: 4\u201310PM | Sunday: 4\u20139PM",
"working_hours": {
"Monday": "11:30AM\u20139PM",
"Tuesday": "11:30AM\u20139PM",
"Wednesday": "11:30AM\u20139PM",
"Thursday": "11:30AM\u20139PM",
"Friday": "11:30AM\u201310PM",
"Saturday": "4\u201310PM",
"Sunday": "4\u20139PM"
},
"business_status": "OPERATIONAL",
"about": {
"Service options": {
"Takeout": true,
"Dine-in": true,
"Delivery": false
},
"Health & safety": {
"Mask required": true,
"Staff wear masks": true,
"Staff get temperature checks": true,
"Staff required to disinfect surfaces between visits": true
},
"Highlights": {
"Great dessert": true
},
"Popular for": {
"Lunch": true,
"Dinner": true,
"Solo dining": true
},
"Accessibility": {
"Wheelchair accessible entrance": true,
"Wheelchair accessible seating": true
},
"Offerings": {
"Alcohol": true,
"Beer": true,
"Cocktails": true,
"Coffee": true,
"Hard liquor": true,
"Healthy options": true,
"Late-night food": true,
"Small plates": true,
"Vegetarian options": true,
"Wine": true
},
"Dining options": {
"Lunch": true,
"Dinner": true,
"Dessert": true,
"Seating": true
},
"Amenities": {
"Bar onsite": true,
"High chairs": true,
"Restroom": true,
"Wi-Fi": true
},
"Atmosphere": {
"Cozy": true,
"Romantic": true,
"Upscale": true
},
"Crowd": {
"Family-friendly": true,
"Groups": true,
"Tourists": true
},
"Planning": {
"Lunch reservations recommended": true,
"Dinner reservations recommended": true,
"Accepts reservations": true
}
},
"range": "$$$",
"reviews_per_score": {
"1": 27,
"2": 32,
"3": 97,
"4": 408,
"5": 823
},
"reserving_table_link": "https://www.watergrill.com/la#RESERVATIONS",
"booking_appointment_link": "https://www.watergrill.com/la#RESERVATIONS",
"owner_id": "116715188720123884576",
"verified": true,
"owner_title": "Water Grill",
"owner_link": "https://www.google.com/maps/contrib/116715188720123884576",
"location_link": "https://www.google.com/maps/place/Water+Grill/@34.0490403,-118.25470659999999,14z/data=!4m8!1m2!2m1!1sWater+Grill!3m4!1s0x80c2c7b4901ce7c7:0x2ad996c9a82b097c!8m2!3d34.0490403!4d-118.25470659999999"
},
...
]
파이썬 패키지 ► https://pypi.org/project/google-services-api
Google Maps Places API ► https://outscraper.com/google-maps-api
비디오 튜토리얼
자주하는 질문
가장 자주 묻는 질문과 답변
다양한 보호 조치(reCAPTCHA, 동적 콘텐츠, IP 확인 등)로 인해 순수 파이썬으로 구글 지도를 스크래핑하는 것은 어려운 작업입니다. 이러한 이유로 Outscraper와 같은 솔루션을 제공하는 서비스를 활용할 수 있습니다.
파이썬 SDK ~를 사용할 수 있게 해주는 Outscraper의 서비스 그리고 Outscraper의 API. 따라서 파이썬을 사용해 구글 지도 데이터를 추출할 수 있습니다.
Google 지도에 표시된 모든 위치는 Outscraper Google Places API를 사용하여 수집할 수 있습니다. 해당 위치에 속한 모든 데이터가 나열되며, 이를 내보낼 수 있습니다.
Outscraper Google Maps 리뷰 API를 사용하면 Python 및 기타 프로그래밍 언어를 통해 리뷰 데이터를 추출할 수 있습니다.
스크래핑은 다음 5단계로 진행됩니다:
1. Python 3 이상과 해당 Python 패키지가 필요합니다. 패키지를 설치하십시오.
2. Outscraper 프로필 페이지에서 API 키를 받아오세요.
3. 패키지를 임포트하고 키로 초기화합니다.
4. 링크, 장소 ID 또는 이름을 입력하여 위치를 지정합니다.
5. 리뷰가 가져올 때까지 몇 초간 기다립니다.
0 Comments