{"id":21130404,"url":"https://github.com/serpapi/google-search-results-java","last_synced_at":"2025-07-09T01:33:26.446Z","repository":{"id":40799519,"uuid":"117773818","full_name":"serpapi/google-search-results-java","owner":"serpapi","description":"Google Search Results JAVA API via SerpApi","archived":false,"fork":false,"pushed_at":"2023-12-27T22:07:05.000Z","size":266,"stargazers_count":43,"open_issues_count":3,"forks_count":24,"subscribers_count":9,"default_branch":"master","last_synced_at":"2025-04-04T14:21:37.899Z","etag":null,"topics":["data-extraction","data-scraping","java","java-api","json","serp-api","serpapi","web-scraping","webscraping"],"latest_commit_sha":null,"homepage":"https://serpapi.com","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/serpapi.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2018-01-17T02:46:52.000Z","updated_at":"2025-03-21T06:32:16.000Z","dependencies_parsed_at":"2023-12-27T23:53:35.465Z","dependency_job_id":null,"html_url":"https://github.com/serpapi/google-search-results-java","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"purl":"pkg:github/serpapi/google-search-results-java","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/serpapi%2Fgoogle-search-results-java","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/serpapi%2Fgoogle-search-results-java/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/serpapi%2Fgoogle-search-results-java/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/serpapi%2Fgoogle-search-results-java/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/serpapi","download_url":"https://codeload.github.com/serpapi/google-search-results-java/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/serpapi%2Fgoogle-search-results-java/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":264375558,"owners_count":23598398,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["data-extraction","data-scraping","java","java-api","json","serp-api","serpapi","web-scraping","webscraping"],"created_at":"2024-11-20T05:33:01.397Z","updated_at":"2025-07-09T01:33:26.176Z","avatar_url":"https://github.com/serpapi.png","language":"Java","readme":"# Google Search Results JAVA API\n\n![test](https://github.com/serpapi/google-search-results-java/workflows/test/badge.svg)\n\nThis Java package enables to scrape and parse Google, Bing and Baidu search results using [SerpApi](https://serpapi.com). Feel free to fork this repository to add more backends.\n\nThis project is an implementation of SerpApi in Java 7.\nThis code depends on GSON for efficient JSON processing.\nThe HTTP response are converted to JSON Object.\n\nAn example is provided in the test.\n@see src/test/java/GoogleSearchImplementationTest.java\n\n[The full documentation is available here.](https://serpapi.com/search-api)\n\n## Requirements\n\nRuntime:\n - Java / JDK 8+ (https://www.java.com/en/download/)\n   Older version of java do not support HTTPS protocol. \n   The SSLv3 is buggy which leads to Java raising this exception: javax.net.ssl.SSLHandshakeException\n\nFor development:\n - Gradle 6.7+ (https://gradle.org/install/) \n\n## Maven / Gradle support\n\nEdit your build.gradle file\n```java\nrepositories {\n    maven { url \"https://jitpack.io\" }\n}\n\ndependencies {\n    implementation 'com.github.serpapi:google-search-results-java:2.0.2'\n}\n```\n\nTo list all the version available.\nhttps://jitpack.io/api/builds/com.github.serpapi/google-search-results-java\n\nNote: jitpack.io enables to download maven package directly from github release.\n\n## Quick start\n\nTo get started with this project in Java. \nWe provided a fully working example.\n```bash\ngit clone https://github.com/serpapi/google_search_results_java.git\ncd google_search_results_java/demo\nmake run api_key=\u003cyour private key\u003e\n```\nNote: You need an account with SerpApi to obtain this key from: https://serpapi.com/dashboard\n\nfile: demo/src/main/java/demo/App.java\n```java\npublic class App {\n    public static void main(String[] args) throws SerpApiSearchException {\n        if(args.length != 1) {\n            System.out.println(\"Usage: app \u003csecret api key\u003e\");\n            System.exit(1);\n        }\n\n        String location = \"Austin,Texas\";\n        System.out.println(\"find the first Coffee in \" + location);\n\n        // parameters\n        Map\u003cString, String\u003e parameter = new HashMap\u003c\u003e();\n        parameter.put(\"q\", \"Coffee\");\n        parameter.put(\"location\", location);\n        parameter.put(GoogleSearch.SERP_API_KEY_NAME, args[0]);\n\n        // Create search\n        GoogleSearch search = new GoogleSearch(parameter);\n\n        try {\n            // Execute search\n            JsonObject data = search.getJson();\n\n            // Decode response\n            JsonArray results = (JsonArray) data.get(\"local_results\");\n            JsonObject first_result = results.get(0).getAsJsonObject();\n            System.out.println(\"first coffee: \" + first_result.get(\"title\").getAsString() + \" in \" + location);\n        } catch (SerpApiSearchException e) {\n            System.out.println(\"oops exception detected!\");\n            e.printStackTrace();\n        }\n    }\n}\n```\n\nThis example runs a search about \"coffee\" using your secret api key.\n\nThe Serp API service (backend)\n - searches on Google using the query: q = \"coffee\"\n - parses the messy HTML responses\n - return a standardized JSON response\nThe class GoogleSearch\n - Format the request to Serp API server\n - Execute GET http request\n - Parse JSON into Ruby Hash using JSON standard library provided by Ruby\nEt voila..\n\nAlternatively, you can search:\n - Bing using BingSearch class\n - Baidu using BaiduSearch class\n\nSee the playground to generate your code.\n https://serpapi.com/playground\n\n## Example\n * [How to set SERP API key](#how-to-set-serp-api-key)\n * [Search API capability](#search-api-capability)\n * [Example by specification](#example-by-specification)\n * [Location API](#location-api)\n * [Search Archive API](#search-archive-api)\n * [Account API](#account-api)\n\n## How to set SERP API key\nThe Serp API key can be set globally using a singleton pattern.\n```java\nGoogleSearch.serp_api_key_default = \"Your Private Key\"\nsearch = GoogleSearch(parameter)\n```\nOr the Serp API key can be provided for each query.\n\n```java\nsearch = GoogleSearch(parameter, \"Your Private Key\")\n```\n\n## Example with all params and all outputs\n\n```java\nquery_parameter = {\n  \"q\": \"query\",\n  \"google_domain\": \"Google Domain\",\n  \"location\": \"Location Requested\",\n  \"device\": device,\n  \"hl\": \"Google UI Language\",\n  \"gl\": \"Google Country\",\n  \"safe\": \"Safe Search Flag\",\n  \"num\": \"Number of Results\",\n  \"start\": \"Pagination Offset\",\n  \"serp_api_key\": \"Your SERP API Key\",\n  \"tbm\": \"nws|isch|shop\",\n  \"tbs\": \"custom to be search criteria\",\n  \"async\": true|false,    // allow async request - non-blocker\n  \"output\": \"json|html\",  // output format\n}\n\nquery = GoogleSearch.new(query_parameter)\nquery.parameter.put(\"location\", \"Austin,Texas\")\n\nString html_results = query.getHtml()\nJsonObject json_results = query.getJson()\n```\n\n### Example by specification\n\nWe love true open source, continuous integration and Test Drive Development (TDD). \n We are using RSpec to test [our infrastructure around the clock](https://travis-ci.org/serpapi/google-search-results-ruby) to achieve the best QoS (Quality Of Service).\n \nThe directory test/ includes specification/examples.\n\nTo run the test:\n```gradle test```\n\n\n### Location API\n\n```java\nGoogleSearch search = new GoogleSearch(new HashMap\u003cString, String());\nJsonArray locationList = search.getLocation(\"Austin\", 3);\nSystem.out.println(locationList.toString());\n```\nit prints the first 3 location matching Austin (Texas, Texas, Rochester)\n\n### Search Archive API\n\nLet's run a search to get a search_id.\n```java\nMap\u003cString, String\u003e parameter = new HashMap\u003c\u003e();\nparameter.put(\"q\", \"Coffee\");\nparameter.put(\"location\", \"Austin,Texas\");\n\nGoogleSearch search = new GoogleSearch(parameter);\nJsonObject result = search.getJson();\nint search_id = result.get(\"search_metadata\").getAsJsonObject().get(\"id\").getAsInt();\n```\n\nNow let retrieve the previous search from the archive.\n```java\nJsonObject archived_result = search.getSearchArchive(search_id);\nSystem.out.println(archived_result.toString());\n```\nit prints the search from the archive.\n\n### Account API\nGet account API\n```java\nGoogleSearch.serp_api_key_default = \"Your Private Key\"\nGoogleSearch search = new GoogleSearch();\nJsonObject info = search.getAccount();\nSystem.out.println(info.toString());\n```\nit prints your account information.\n\n## Build project\n\n### How to build from the source ?\n\nYou must clone this repository.\n```bash\ngit clone https://github.com/serpapi/google_search_results_java.git\n```\nBuild the jar file.\n```bash\ngradle build\n```\nCopy the jar to your project lib/ directory.\n```bash\ncp build/libs/google_search_results_java.jar path/to/yourproject/lib\n```\n\n### How to test ?\n\n```bash\nmake test\n```\n\n### Conclusion\n\nThis service supports Google Images, News, Shopping.\nTo enable a type of search, the field tbm (to be matched) must be set to:\n\n * isch: Google Images API.\n * nws: Google News API.\n * shop: Google Shopping API.\n * any other Google service should work out of the box.\n * (no tbm parameter): regular Google Search.\n\n[The full documentation is available here.](https://serpapi.com/search-api)\n\nIssue\n---\n### SSL handshake error.\n\n#### symptom\n\njavax.net.ssl.SSLHandshakeException\n\n#### cause\nSerpApi is using HTTPS / SSLv3. Older JVM version do not support this protocol because it's more recent. \n\n#### solution\nUpgrade java to 1.8_201+ (which is recommended by Oracle).\n\n * On OSX you can switch versino of Java.\n```sh\nexport JAVA_HOME=`/usr/libexec/java_home -v 1.8.0_201`\njava -version\n```\n\n * On Windows manually upgrade your JDK / JVM to the latest.\n\n * On Linux, Oracle JDK 8 (1.8_151+) seems to work fine.\nsee: https://travis-ci.org/serpapi/google-search-results-java\n\nChangelog\n---\n- 2.0.1 update gradle 6.7.1 \n- 2.0 refractor API : suffix SearchResults renamed Search\n- 1.4 Add support for Yandex, Yahoo, Ebay\n- 1.3 Add support for Bing and Baidu\n- 1.2 Add support for location API, account API, search API\n\nSource\n---\n * http://www.baeldung.com/java-http-request\n * https://github.com/google/gson\n\nAuthor\n---\nVictor Benarbia - victor@serpapi.com\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fserpapi%2Fgoogle-search-results-java","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fserpapi%2Fgoogle-search-results-java","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fserpapi%2Fgoogle-search-results-java/lists"}