如何刮取Google Maps Description Place?

时间:2019-06-02 09:49:44

标签: java google-maps web-scraping

我一直在搜索如何获取Google Maps每个位置的描述,因为Google Place不提供描述。 我想知道是否可以使用JAVA刮取每个地方的描述。这仅用于教学目的。 我附上一张照片。

https://subefotos.com/ver/?4337c39301538269fe1c47ca48906c90o.png

谢谢。

2 个答案:

答案 0 :(得分:1)

请注意,从maps.google.com抓取数据可能违反产品的Terms of Service,关于您的关注,您正确地知道该功能目前在Google Maps API中不可用已经是为此功能提交的功能请求,我还看到您对该问题已 + 1'd 以便接收更新,对于希望将此功能合并到其他开发人员中的其他开发人员Google Maps Platform API,您也可以在此处加注星标-https://issuetracker.google.com/35822953以接收更新。

请注意,对Google Maps Platform API进行功能请求的最佳位置是将其提交到Issue Tracker中,以便工程师审查您的请求的可行性。

答案 1 :(得分:0)

您可以查询链接:https://www.google.com/maps/place/data=!4m5!3m4!1s{DATA_ID}!8m2!3d{latitude}!4d{longitude}?hl=en

  • DATA_ID:例如0x89c259a61c75684f%3a0x79d31adb123348d2

如果您随后检查页面源代码,您将看到所有数据都位于 window.APP_INITIALIZATION_STATE 块内,该块包含所有地图数据(包括您感兴趣的描述)。你只需要解析它。

或者,您也可以使用第三方解决方案,例如 SerpApi。这是一个免费试用的付费 API。

示例 java 代码(也可在其他库中使用):

Map<String, String> parameter = new HashMap<>();

parameter.put("api_key", "secret_api_key");
parameter.put("engine", "google_maps");
parameter.put("google_domain", "google.com");
parameter.put("hl", "en");
parameter.put("data", "!4m5!3m4!1s0x89c259a61c75684f%3a0x79d31adb123348d2!8m2!3d40.7457413!4d-73.98820049999999");
parameter.put("type", "place");

GoogleSearch search = new GoogleSearch(parameter);

try
{
  JsonObject results = search.getJson();
}
catch (SerpApiClientException ex)
{
  Console.WriteLine("Exception:");
  Console.WriteLine(ex.ToString());
}

示例 JSON 输出:

{
  "place_results": {
    "title": "Stumptown Coffee Roasters",
    "data_id": "0x89c259a61c75684f:0x79d31adb123348d2",
    "reviews_link": "https://serpapi.com/search.json?engine=google_maps_reviews&hl=en&place_id=0x89c259a61c75684f%3A0x79d31adb123348d2",
    "gps_coordinates": {
      "latitude": 40.7457399,
      "longitude": -73.9882272
    },
    "place_id_search": "https://serpapi.com/search.json?data=%214m5%213m4%211s0x89c259a61c75684f%3A0x79d31adb123348d2%218m2%213d40.7457399%214d-73.9882272&engine=google_maps&google_domain=google.com&hl=en&type=place",
    "thumbnail": "https://lh5.googleusercontent.com/p/AF1QipOcnxJgzyrk5HzIJES2am5zeGjwzo2oMQt_tNMj=w114-h86-k-no",
    "rating": 4.6,
    "reviews": 1335,
    "price": "$$",
    "type": [
      "Coffee shop",
      "Cafe",
      "Coffee store",
      "Tea store"
    ],
    "description": "Coffee bar serving direct-trade java. Coffee bar chain offering house-roasted direct-trade coffee, along with brewing gear & whole beans",
    "service_options": {
      "takeout": true,
      "delivery": false
    },
    "extensions": [
      {
        "highlights": [
          "Fast service",
          "Fireplace",
          "Great coffee",
          "Great tea selection",
          "Live performances"
        ]
      },
      {
        "popular_for": [
          "Solo dining",
          "Good for working on laptop"
        ]
      },
      {
        "accessibility": [
          "Wheelchair accessible entrance",
          "Wheelchair accessible restroom"
        ]
      },
      {
        "offerings": [
          "Coffee",
          "Quick bite"
        ]
      },
      {
        "dining_options": [
          "Lunch",
          "Dinner",
          "Dessert"
        ]
      },
      {
        "amenities": [
          "Restroom"
        ]
      },
      {
        "atmosphere": [
          "Casual",
          "Cozy"
        ]
      },
      {
        "crowd": [
          "College students",
          "Tourists"
        ]
      },
      {
        "payments": [
          "NFC mobile payments"
        ]
      }
    ],
    "address": "18 W 29th St, New York, NY 10001",
    "website": "https://www.stumptowncoffee.com/locations/newyork/ace-nyc",
    "phone": "(855) 711-3385",
    "hours": [
      {
        "saturday": "8AM–4PM"
      },
      {
        "sunday": "8AM–4PM"
      },
      {
        "monday": "7AM–3PM"
      },
      {
        "tuesday": "7AM–3PM"
      },
      {
        "wednesday": "7AM–3PM"
      },
      {
        "thursday": "7AM–3PM"
      },
      {
        "friday": "7AM–3PM"
      }
    ],
    "images": [
      {
        "title": "All",
        "thumbnail": "https://lh5.googleusercontent.com/p/AF1QipOcnxJgzyrk5HzIJES2am5zeGjwzo2oMQt_tNMj=w397-h298-k-no"
      },
      {
        "title": "Menu",
        "thumbnail": "https://lh5.googleusercontent.com/p/AF1QipO-7FZuS6-BQu_HrJN4qZ7fjC-mhpnfLCpPhXN-=w529-h298-k-no"
      },
      {
        "title": "Food & drink",
        "thumbnail": "https://lh5.googleusercontent.com/p/AF1QipPCPSYLktGESHtVoEyffOsnYxtzyMjR1WjTbHPV=w397-h298-k-no"
      },
      {
        "title": "Vibe",
        "thumbnail": "https://lh5.googleusercontent.com/p/AF1QipOVJ8ipbrVb7ct8_ssjdsWncKJBUUBux2QAK0ws=w397-h298-k-no"
      },
      {
        "title": "Street View & 360°",
        "thumbnail": "https://lh5.googleusercontent.com/p/AF1QipN_Slp5SIECK4LgVKUWCSmzL99kCEsJmDqZz-Rc=w224-h298-k-no-pi-18.172167-ya190.9134-ro3.5189135-fo100"
      },
      {
        "title": "Videos",
        "thumbnail": "https://lh5.googleusercontent.com/p/AF1QipOOPV7oy7w5070nMraA3lpk8GpV0GiE0rYHUW9S=w224-h398-k-no"
      }
    ],
    "user_reviews": {
      "summary": [
        {
          "snippet": "\"The baristas here are pretty cool people who pull excellent espresso shots.\""
        },
        {
          "snippet": "\"Nice space and good varied of coffee, drinks, baked goods and good service :)\""
        },
        {
          "snippet": "\"It has amazing food at affordable prices and the staff is super friendly.\""
        }
      ],
      "most_relevant": [
        {
          "username": "HerbertTomlinson O",
          "rating": 4,
          "description": "Finally, I found the best coffee shop today. Their choice of music is usually blasting from the past which was really relaxing and made me stay longer. There are tables for lovers and also for group of friends. The coffees and foods here are very affordable and well worth the money. You can't go wrong with this coffee shop. This is very worth to visit.",
          "date": "2 months ago"
        },
        {
          "username": "Izaac Collier",
          "rating": 5,
          "description": "I am not into coffee but one of my friends invited me here. As I looked the menu, I was convinced, so I ordered one for me. The food was tasty and the staff were very friendly and accommodating. The ambience was very cosy and comfortable. The coffee was great and super tasty. I will recommend this and will visit again!",
          "date": "a month ago"
        },
        {
          "username": "Kristin Franco",
          "rating": 5,
          "description": "The ambience was very cozy and comfortable. The coffee was great. Even if it was my first time to drink their coffee, I could really appreciate the taste and it became my favorite flavor then. I will recommend and will visit again. Thank you so much for the accommodating staff!",
          "date": "2 months ago"
        },
        {
          "username": "Jodi Maldonado",
          "rating": 4,
          "description": "You're the brightest of the bunch! This coffee shop appeals to me because it serves coffee and pastries that I love. It's not great, but it's not bad either. You've put in a lot of effort to earn the right to be remembered by a large number of people! Expect me to return and tell my coworkers about your idea.",
          "date": "3 months ago"
        },
        {
          "username": "Poppie Hodge",
          "rating": 5,
          "description": "Nice coffee bar! Looking for a nice coffee and cake for my parents, and I found this coffee shop near my house. Coffee and cakes were so sweet, and the staff are very polite and supportive. The place is so relaxing and so clean. Highly suggested to all of you!",
          "date": "2 months ago"
        },
        {
          "username": "Elba Haire",
          "rating": 4,
          "description": "Great biscuits, very good omelette, and the corned beef hash was the best!!! Wife had eggs Benedict and that was excellent too. Not much atmosphere but who cares when your face is buried in your plate!! Recommend strongly. Moderate prices, good value.",
          "date": "3 months ago"
        },
        {
          "username": "Tea Maldonado",
          "rating": 5,
          "description": "It's clean, well run, and the owners are genuinely nice people. A highly recommendable coffee shop!",
          "date": "3 weeks ago"
        },
        {
          "username": "Blanche Bibbins",
          "rating": 4,
          "description": "We shared the Reuben as recommended by the waitress. It was tasty and a perfect size to share. If you are looking for an interesting place for a quick lunch in the historic district of New york, this is a good place to try.",
          "date": "3 months ago"
        }
      ]
    },
    "people_also_search_for": [
      {
        "search_term": "Coffee shops",
        "local_results": [
          {
            "position": 1,
            "title": "Culture Espresso",
            "data_id": "0x89c259aa4c38ca75:0x88ca3d6ff537d876",
            "reviews_link": "https://serpapi.com/search.json?engine=google_maps_reviews&hl=en&place_id=0x89c259aa4c38ca75%3A0x88ca3d6ff537d876",
            "gps_coordinates": {
              "latitude": 40.7520746,
              "longitude": -73.9857387
            },
            "place_id_search": "https://serpapi.com/search.json?data=%214m5%213m4%211s0x89c259aa4c38ca75%3A0x88ca3d6ff537d876%218m2%213d40.7520746%214d-73.9857387&engine=google_maps&google_domain=google.com&hl=en&type=place",
            "rating": 4.5,
            "reviews": 1031,
            "thumbnail": "https://lh5.googleusercontent.com/p/AF1QipOfqz4XRKZLCTff5ZIAT5CnwAMivcRhzvw6TYqA=w152-h152-k-no-pi0-ya240-ro0-fo100",
            "type": [
              "Coffee shop",
              "Bakery",
              "Cookies"
            ]
          },
          {
            "position": 2,
            "title": "Café Grumpy - Fashion District",
            "data_id": "0x89c259ab6335319b:0x394cadbea63ab640",
            "reviews_link": "https://serpapi.com/search.json?engine=google_maps_reviews&hl=en&place_id=0x89c259ab6335319b%3A0x394cadbea63ab640",
            "gps_coordinates": {
              "latitude": 40.7541667,
              "longitude": -73.98888889999999
            },
            "place_id_search": "https://serpapi.com/search.json?data=%214m5%213m4%211s0x89c259ab6335319b%3A0x394cadbea63ab640%218m2%213d40.7541667%214d-73.98888889999999&engine=google_maps&google_domain=google.com&hl=en&type=place",
            "rating": 4.4,
            "reviews": 549,
            "thumbnail": "https://lh5.googleusercontent.com/p/AF1QipNDP9YNNEkQbsYghI0nueHm6u7GsouIErVSbrwk=w152-h152-n-k-no",
            "type": [
              "Coffee shop",
              "Cafe",
              "Espresso bar"
            ]
          },
          {
            "position": 3,
            "title": "Gregorys Coffee",
            "data_id": "0x89c259a72946c6f5:0xf883630efdc8c731",
            "reviews_link": "https://serpapi.com/search.json?engine=google_maps_reviews&hl=en&place_id=0x89c259a72946c6f5%3A0xf883630efdc8c731",
            "gps_coordinates": {
              "latitude": 40.740965599999996,
              "longitude": -73.9855511
            },
            "place_id_search": "https://serpapi.com/search.json?data=%214m5%213m4%211s0x89c259a72946c6f5%3A0xf883630efdc8c731%218m2%213d40.740965599999996%214d-73.9855511&engine=google_maps&google_domain=google.com&hl=en&type=place",
            "rating": 4.3,
            "reviews": 494,
            "thumbnail": "http://lh6.googleusercontent.com/proxy/qR76zBM64Gj706wDlRH2xgKfaAExaRw3xMGLGRuZwGXPxkCR23iZwkrLCR8wrCEMEPWSx_OLhLQUEToJXc7vYWuG28Nz_bFqGZWrRZQ-4raYVAa59Q1HOIWwxeBkSbsdbZvmbcsIjZ2_AFMEPKyhTlCoe5IQ2reO9hVNM-1k8V0i=w152-h152-n-k-no",
            "type": [
              "Coffee shop"
            ]
          },
          {
            "position": 4,
            "title": "Blue Bottle Coffee",
            "data_id": "0x89c258feda68c787:0xe0c78830b997f960",
            "reviews_link": "https://serpapi.com/search.json?engine=google_maps_reviews&hl=en&place_id=0x89c258feda68c787%3A0xe0c78830b997f960",
            "gps_coordinates": {
              "latitude": 40.758208599999996,
              "longitude": -73.9786889
            },
            "place_id_search": "https://serpapi.com/search.json?data=%214m5%213m4%211s0x89c258feda68c787%3A0xe0c78830b997f960%218m2%213d40.758208599999996%214d-73.9786889&engine=google_maps&google_domain=google.com&hl=en&type=place",
            "rating": 4.5,
            "reviews": 742,
            "thumbnail": "https://lh5.googleusercontent.com/p/AF1QipN7oWsSBqHHQC-33qoVXOj78zYG1DWTyB4hwhMh=w152-h152-n-k-no",
            "type": [
              "Coffee shop"
            ]
          }
        ]
      },
      {
        "search_term": "Coffee roasters",
        "local_results": [
          {
            "position": 1,
            "title": "Irving Farm New York",
            "data_id": "0x89c259a1c4280bdf:0xb7d1c448bc0e0f46",
            "reviews_link": "https://serpapi.com/search.json?engine=google_maps_reviews&hl=en&place_id=0x89c259a1c4280bdf%3A0xb7d1c448bc0e0f46",
            "gps_coordinates": {
              "latitude": 40.736810299999995,
              "longitude": -73.9869409
            },
            "place_id_search": "https://serpapi.com/search.json?data=%214m5%213m4%211s0x89c259a1c4280bdf%3A0xb7d1c448bc0e0f46%218m2%213d40.736810299999995%214d-73.9869409&engine=google_maps&google_domain=google.com&hl=en&type=place",
            "rating": 4.2,
            "reviews": 528,
            "thumbnail": "https://lh5.googleusercontent.com/p/AF1QipN8U4YuUu1pS9PxWeJ-C6BcuKz-fo7pGX1qJ3Gk=w152-h152-n-k-no",
            "type": [
              "Coffee shop"
            ]
          },
          {
            "position": 2,
            "title": "Oslo Coffee Roasters",
            "data_id": "0x89c258c73391d667:0xc36a558319ee87cc",
            "reviews_link": "https://serpapi.com/search.json?engine=google_maps_reviews&hl=en&place_id=0x89c258c73391d667%3A0xc36a558319ee87cc",
            "gps_coordinates": {
              "latitude": 40.7691558,
              "longitude": -73.953699
            },
            "place_id_search": "https://serpapi.com/search.json?data=%214m5%213m4%211s0x89c258c73391d667%3A0xc36a558319ee87cc%218m2%213d40.7691558%214d-73.953699&engine=google_maps&google_domain=google.com&hl=en&type=place",
            "rating": 4.6,
            "reviews": 255,
            "thumbnail": "https://lh5.googleusercontent.com/p/AF1QipNRUpYrsCzNyGftbrQKb1KpJnVlQr3u3dquJkTH=w152-h152-n-k-no",
            "type": [
              "Coffee shop",
              "Cafe",
              "Espresso bar"
            ]
          }
        ]
      },
      {
        "search_term": "Other locations for Stumptown",
        "local_results": [
          {
            "position": 1,
            "title": "Stumptown Coffee Roasters",
            "data_id": "0x89c25996d46ccfed:0x3034ad801dc5fcb3",
            "reviews_link": "https://serpapi.com/search.json?engine=google_maps_reviews&hl=en&place_id=0x89c25996d46ccfed%3A0x3034ad801dc5fcb3",
            "gps_coordinates": {
              "latitude": 40.7328275,
              "longitude": -73.9979664
            },
            "place_id_search": "https://serpapi.com/search.json?data=%214m5%213m4%211s0x89c25996d46ccfed%3A0x3034ad801dc5fcb3%218m2%213d40.7328275%214d-73.9979664&engine=google_maps&google_domain=google.com&hl=en&type=place",
            "rating": 4.5,
            "reviews": 1041,
            "thumbnail": "https://lh5.googleusercontent.com/p/AF1QipNg2KVi1X1frTSf4YtPsv0U-rp1I-BlExfvWje3=w152-h152-n-k-no",
            "type": [
              "Coffee shop",
              "Cafe",
              "Tea store",
              "Coffee store"
            ]
          }
        ]
      }
    ]
  }
}

查看documentation了解更多详情。

免责声明:我在 SerpApi 工作。