├── .github └── workflows │ └── go.yml ├── .gitignore ├── LICENSE ├── README.md ├── go.mod ├── go.sum ├── internal ├── parse │ └── parse.go └── util │ └── util.go └── pkg ├── app ├── app.go └── app_test.go ├── category ├── category.go └── category_test.go ├── collection ├── collection.go └── collection_test.go ├── developer ├── developer.go └── developer_test.go ├── reviews ├── results.go ├── reviews.go └── reviews_test.go ├── scraper ├── results.go └── scraper.go ├── search ├── search.go └── search_test.go ├── similar ├── similar.go └── similar_test.go ├── store ├── age.go ├── category.go ├── collections.go └── sort.go └── suggest ├── suggest.go └── suggest_test.go /.github/workflows/go.yml: -------------------------------------------------------------------------------- 1 | name: Go 2 | on: 3 | push: 4 | pull_request: 5 | schedule: 6 | - cron: '0 5 * * *' 7 | 8 | jobs: 9 | 10 | test: 11 | name: Test 12 | runs-on: ubuntu-latest 13 | steps: 14 | 15 | - name: Set up Go 1.12 16 | uses: actions/setup-go@v2 17 | with: 18 | go-version: 1.13 19 | id: go 20 | 21 | - name: Check out code into the Go module directory 22 | uses: actions/checkout@v2 23 | 24 | - name: Test 25 | run: go test -covermode=count -coverprofile=coverage.out ./... 26 | 27 | - name: Convert coverage to lcov 28 | uses: jandelgado/gcov2lcov-action@v1.0.5 29 | with: 30 | infile: coverage.out 31 | outfile: coverage.lcov 32 | 33 | - name: Coveralls 34 | uses: coverallsapp/github-action@master 35 | with: 36 | github-token: ${{ secrets.GITHUB_TOKEN }} 37 | path-to-lcov: coverage.lcov 38 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Binaries for programs and plugins 2 | *.exe 3 | *.exe~ 4 | *.dll 5 | *.so 6 | *.dylib 7 | 8 | # Test binary, build with `go test -c` 9 | *.test 10 | 11 | # Output of the go coverage tool, specifically when used with LiteIDE 12 | *.out 13 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU LESSER GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | 9 | This version of the GNU Lesser General Public License incorporates 10 | the terms and conditions of version 3 of the GNU General Public 11 | License, supplemented by the additional permissions listed below. 12 | 13 | 0. Additional Definitions. 14 | 15 | As used herein, "this License" refers to version 3 of the GNU Lesser 16 | General Public License, and the "GNU GPL" refers to version 3 of the GNU 17 | General Public License. 18 | 19 | "The Library" refers to a covered work governed by this License, 20 | other than an Application or a Combined Work as defined below. 21 | 22 | An "Application" is any work that makes use of an interface provided 23 | by the Library, but which is not otherwise based on the Library. 24 | Defining a subclass of a class defined by the Library is deemed a mode 25 | of using an interface provided by the Library. 26 | 27 | A "Combined Work" is a work produced by combining or linking an 28 | Application with the Library. The particular version of the Library 29 | with which the Combined Work was made is also called the "Linked 30 | Version". 31 | 32 | The "Minimal Corresponding Source" for a Combined Work means the 33 | Corresponding Source for the Combined Work, excluding any source code 34 | for portions of the Combined Work that, considered in isolation, are 35 | based on the Application, and not on the Linked Version. 36 | 37 | The "Corresponding Application Code" for a Combined Work means the 38 | object code and/or source code for the Application, including any data 39 | and utility programs needed for reproducing the Combined Work from the 40 | Application, but excluding the System Libraries of the Combined Work. 41 | 42 | 1. Exception to Section 3 of the GNU GPL. 43 | 44 | You may convey a covered work under sections 3 and 4 of this License 45 | without being bound by section 3 of the GNU GPL. 46 | 47 | 2. Conveying Modified Versions. 48 | 49 | If you modify a copy of the Library, and, in your modifications, a 50 | facility refers to a function or data to be supplied by an Application 51 | that uses the facility (other than as an argument passed when the 52 | facility is invoked), then you may convey a copy of the modified 53 | version: 54 | 55 | a) under this License, provided that you make a good faith effort to 56 | ensure that, in the event an Application does not supply the 57 | function or data, the facility still operates, and performs 58 | whatever part of its purpose remains meaningful, or 59 | 60 | b) under the GNU GPL, with none of the additional permissions of 61 | this License applicable to that copy. 62 | 63 | 3. Object Code Incorporating Material from Library Header Files. 64 | 65 | The object code form of an Application may incorporate material from 66 | a header file that is part of the Library. You may convey such object 67 | code under terms of your choice, provided that, if the incorporated 68 | material is not limited to numerical parameters, data structure 69 | layouts and accessors, or small macros, inline functions and templates 70 | (ten or fewer lines in length), you do both of the following: 71 | 72 | a) Give prominent notice with each copy of the object code that the 73 | Library is used in it and that the Library and its use are 74 | covered by this License. 75 | 76 | b) Accompany the object code with a copy of the GNU GPL and this license 77 | document. 78 | 79 | 4. Combined Works. 80 | 81 | You may convey a Combined Work under terms of your choice that, 82 | taken together, effectively do not restrict modification of the 83 | portions of the Library contained in the Combined Work and reverse 84 | engineering for debugging such modifications, if you also do each of 85 | the following: 86 | 87 | a) Give prominent notice with each copy of the Combined Work that 88 | the Library is used in it and that the Library and its use are 89 | covered by this License. 90 | 91 | b) Accompany the Combined Work with a copy of the GNU GPL and this license 92 | document. 93 | 94 | c) For a Combined Work that displays copyright notices during 95 | execution, include the copyright notice for the Library among 96 | these notices, as well as a reference directing the user to the 97 | copies of the GNU GPL and this license document. 98 | 99 | d) Do one of the following: 100 | 101 | 0) Convey the Minimal Corresponding Source under the terms of this 102 | License, and the Corresponding Application Code in a form 103 | suitable for, and under terms that permit, the user to 104 | recombine or relink the Application with a modified version of 105 | the Linked Version to produce a modified Combined Work, in the 106 | manner specified by section 6 of the GNU GPL for conveying 107 | Corresponding Source. 108 | 109 | 1) Use a suitable shared library mechanism for linking with the 110 | Library. A suitable mechanism is one that (a) uses at run time 111 | a copy of the Library already present on the user's computer 112 | system, and (b) will operate properly with a modified version 113 | of the Library that is interface-compatible with the Linked 114 | Version. 115 | 116 | e) Provide Installation Information, but only if you would otherwise 117 | be required to provide such information under section 6 of the 118 | GNU GPL, and only to the extent that such information is 119 | necessary to install and execute a modified version of the 120 | Combined Work produced by recombining or relinking the 121 | Application with a modified version of the Linked Version. (If 122 | you use option 4d0, the Installation Information must accompany 123 | the Minimal Corresponding Source and Corresponding Application 124 | Code. If you use option 4d1, you must provide the Installation 125 | Information in the manner specified by section 6 of the GNU GPL 126 | for conveying Corresponding Source.) 127 | 128 | 5. Combined Libraries. 129 | 130 | You may place library facilities that are a work based on the 131 | Library side by side in a single library together with other library 132 | facilities that are not Applications and are not covered by this 133 | License, and convey such a combined library under terms of your 134 | choice, if you do both of the following: 135 | 136 | a) Accompany the combined library with a copy of the same work based 137 | on the Library, uncombined with any other library facilities, 138 | conveyed under the terms of this License. 139 | 140 | b) Give prominent notice with the combined library that part of it 141 | is a work based on the Library, and explaining where to find the 142 | accompanying uncombined form of the same work. 143 | 144 | 6. Revised Versions of the GNU Lesser General Public License. 145 | 146 | The Free Software Foundation may publish revised and/or new versions 147 | of the GNU Lesser General Public License from time to time. Such new 148 | versions will be similar in spirit to the present version, but may 149 | differ in detail to address new problems or concerns. 150 | 151 | Each version is given a distinguishing version number. If the 152 | Library as you received it specifies that a certain numbered version 153 | of the GNU Lesser General Public License "or any later version" 154 | applies to it, you have the option of following the terms and 155 | conditions either of that published version or of any later version 156 | published by the Free Software Foundation. If the Library as you 157 | received it does not specify a version number of the GNU Lesser 158 | General Public License, you may choose any version of the GNU Lesser 159 | General Public License ever published by the Free Software Foundation. 160 | 161 | If the Library as you received it specifies that a proxy can decide 162 | whether future versions of the GNU Lesser General Public License shall 163 | apply, that proxy's public statement of acceptance of any version is 164 | permanent authorization for you to choose that version for the 165 | Library. 166 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # google-play-scraper 2 | 3 | [![GoDoc](https://godoc.org/github.com/n0madic/google-play-scraper/pkg?status.svg)](https://godoc.org/github.com/n0madic/google-play-scraper/pkg) 4 | [![Go Report Card](https://goreportcard.com/badge/github.com/n0madic/google-play-scraper)](https://goreportcard.com/report/github.com/n0madic/google-play-scraper) 5 | [![Coverage Status](https://coveralls.io/repos/github/n0madic/google-play-scraper/badge.svg?branch=master)](https://coveralls.io/github/n0madic/google-play-scraper?branch=master) 6 | 7 | Golang scraper to get data from Google Play Store 8 | 9 | This project is inspired by the [google-play-scraper](https://github.com/facundoolano/google-play-scraper) node.js project 10 | 11 | ## Installation 12 | 13 | ```shell 14 | go get -u github.com/n0madic/google-play-scraper/... 15 | ``` 16 | 17 | ## Usage 18 | 19 | ### Get app details 20 | 21 | Retrieves the full detail of an application. 22 | 23 | ```go 24 | package main 25 | 26 | import ( 27 | "github.com/davecgh/go-spew/spew" 28 | "github.com/n0madic/google-play-scraper/pkg/app" 29 | ) 30 | 31 | func main() { 32 | a := app.New("com.google.android.googlequicksearchbox", app.Options{ 33 | Country: "us", 34 | Language: "us", 35 | }) 36 | err := a.LoadDetails() 37 | if err != nil { 38 | panic(err) 39 | } 40 | err = a.LoadPermissions() 41 | if err != nil { 42 | panic(err) 43 | } 44 | spew.Dump(a) 45 | } 46 | ``` 47 | 48 | ### Search apps 49 | 50 | Retrieves a list of apps that results of searching by the given term. 51 | 52 | ```go 53 | package main 54 | 55 | import ( 56 | "fmt" 57 | 58 | "github.com/n0madic/google-play-scraper/pkg/search" 59 | ) 60 | 61 | func main() { 62 | query := search.NewQuery("game", search.PricePaid, 63 | search.Options{ 64 | Country: "ru", 65 | Language: "us", 66 | Number: 100, 67 | Discount: true, 68 | PriceMax: 100, 69 | ScoreMin: 4, 70 | }) 71 | 72 | err := query.Run() 73 | if err != nil { 74 | panic(err) 75 | } 76 | 77 | errors := query.LoadMoreDetails(20) 78 | if len(errors) > 0 { 79 | panic(errors[0]) 80 | } 81 | 82 | for _, app := range query.Results { 83 | if !app.IAPOffers { 84 | fmt.Println(app.Title, app.URL) 85 | } 86 | } 87 | } 88 | ``` 89 | 90 | ### Get category 91 | 92 | Returns a list of clusters for the specified application category. 93 | 94 | ```go 95 | package main 96 | 97 | import ( 98 | "fmt" 99 | 100 | "github.com/n0madic/google-play-scraper/pkg/category" 101 | "github.com/n0madic/google-play-scraper/pkg/store" 102 | ) 103 | 104 | func main() { 105 | clusters, err := category.New(store.Game, store.AgeFiveUnder, category.Options{ 106 | Country: "us", 107 | Language: "us", 108 | Number: 100, 109 | }) 110 | if err != nil { 111 | panic(err) 112 | } 113 | 114 | clusterName := "New & updated games" 115 | err = clusters[clusterName].Run() 116 | if err != nil { 117 | panic(err) 118 | } 119 | 120 | for _, app := range clusters[clusterName].Results { 121 | fmt.Println(app.Title, app.URL) 122 | } 123 | } 124 | ``` 125 | 126 | ### Get collection 127 | 128 | Retrieve a list of applications from one of the collections at Google Play. 129 | 130 | ```go 131 | package main 132 | 133 | import ( 134 | "fmt" 135 | 136 | "github.com/n0madic/google-play-scraper/pkg/collection" 137 | "github.com/n0madic/google-play-scraper/pkg/store" 138 | ) 139 | 140 | func main() { 141 | c := collection.New(store.TopNewPaid, collection.Options{ 142 | Country: "uk", 143 | Number: 100, 144 | }) 145 | err := c.Run() 146 | if err != nil { 147 | panic(err) 148 | } 149 | 150 | for _, app := range c.Results { 151 | fmt.Println(app.Title, app.Price, app.URL) 152 | } 153 | } 154 | ``` 155 | 156 | ### Get developer applications 157 | 158 | Returns the list of applications by the given developer name or ID 159 | 160 | ```go 161 | package main 162 | 163 | import ( 164 | "fmt" 165 | 166 | "github.com/n0madic/google-play-scraper/pkg/developer" 167 | ) 168 | 169 | func main() { 170 | dev := developer.New("Google LLC", developer.Options{ 171 | Number: 100, 172 | }) 173 | err := dev.Run() 174 | if err != nil { 175 | panic(err) 176 | } 177 | 178 | for _, app := range dev.Results { 179 | fmt.Println(app.Title, "by", app.Developer, app.URL) 180 | } 181 | } 182 | ``` 183 | 184 | ### Get reviews 185 | 186 | Retrieves a page of reviews for a specific application. 187 | 188 | Note that this method returns reviews in a specific language (english by default), so you need to try different languages to get more reviews. Also, the counter displayed in the Google Play page refers to the total number of 1-5 stars ratings the application has, not the written reviews count. So if the app has 100k ratings, don't expect to get 100k reviews by using this method. 189 | 190 | ```go 191 | package main 192 | 193 | import ( 194 | "fmt" 195 | 196 | "github.com/n0madic/google-play-scraper/pkg/reviews" 197 | ) 198 | 199 | func main() { 200 | r := reviews.New("com.activision.callofduty.shooter", reviews.Options{ 201 | Number: 100, 202 | }) 203 | 204 | err := r.Run() 205 | if err != nil { 206 | panic(err) 207 | } 208 | 209 | for _, review := range r.Results { 210 | fmt.Println(review.Score, review.Text) 211 | } 212 | } 213 | ``` 214 | 215 | ### Get similar 216 | 217 | Returns a list of similar apps to the one specified. 218 | 219 | ```go 220 | package main 221 | 222 | import ( 223 | "fmt" 224 | 225 | "github.com/n0madic/google-play-scraper/pkg/similar" 226 | ) 227 | 228 | func main() { 229 | sim := similar.New("com.android.chrome", similar.Options{ 230 | Number: 100, 231 | }) 232 | err := sim.Run() 233 | if err != nil { 234 | panic(err) 235 | } 236 | 237 | for _, app := range sim.Results { 238 | fmt.Println(app.Title, app.URL) 239 | } 240 | } 241 | ``` 242 | 243 | ### Get suggest 244 | 245 | Given a string returns up to five suggestion to complete a search query term. 246 | 247 | ```go 248 | package main 249 | 250 | import ( 251 | "fmt" 252 | 253 | "github.com/n0madic/google-play-scraper/pkg/suggest" 254 | ) 255 | 256 | func main() { 257 | sug, err := suggest.Get("chrome", suggest.Options{ 258 | Country: "us", 259 | Language: "us", 260 | }) 261 | if err != nil { 262 | panic(err) 263 | } 264 | 265 | for _, s := range sug { 266 | fmt.Println(s) 267 | } 268 | } 269 | ``` 270 | -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module github.com/n0madic/google-play-scraper 2 | 3 | go 1.12 4 | 5 | require ( 6 | github.com/k3a/html2text v1.0.8 7 | github.com/tidwall/gjson v1.14.1 8 | ) 9 | -------------------------------------------------------------------------------- /go.sum: -------------------------------------------------------------------------------- 1 | github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1 h1:EGx4pi6eqNxGaHF6qqu48+N2wcFQ5qg5FXgOdqsJ5d8= 2 | github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY= 3 | github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7C0MuV77Wo= 4 | github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU= 5 | github.com/k3a/html2text v1.0.8 h1:rVanLhKilpnJUJs/CNKWzMC4YaQINGxK0rSG8ssmnV0= 6 | github.com/k3a/html2text v1.0.8/go.mod h1:ieEXykM67iT8lTvEWBh6fhpH4B23kB9OMKPdIBmgUqA= 7 | github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d h1:zE9ykElWQ6/NYmHa3jpm/yHnI4xSofP+UP6SpjHcSeM= 8 | github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc= 9 | github.com/smartystreets/goconvey v1.6.4 h1:fv0U8FUIMPNf1L9lnHLvLhgicrIVChEkdzIKYqbNC9s= 10 | github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA= 11 | github.com/tidwall/gjson v1.14.1 h1:iymTbGkQBhveq21bEvAQ81I0LEBork8BFe1CUZXdyuo= 12 | github.com/tidwall/gjson v1.14.1/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk= 13 | github.com/tidwall/match v1.1.1 h1:+Ho715JplO36QYgwN9PGYNhgZvoUSc9X2c80KVTi+GA= 14 | github.com/tidwall/match v1.1.1/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JTxsfmM= 15 | github.com/tidwall/pretty v1.2.0 h1:RWIZEg2iJ8/g6fDDYzMpobmaoGh5OLl4AXtGUGPcqCs= 16 | github.com/tidwall/pretty v1.2.0/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU= 17 | golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= 18 | golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= 19 | golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 20 | golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= 21 | golang.org/x/tools v0.0.0-20190328211700-ab21143f2384/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= 22 | -------------------------------------------------------------------------------- /internal/parse/parse.go: -------------------------------------------------------------------------------- 1 | package parse 2 | 3 | import ( 4 | "net/url" 5 | "regexp" 6 | "strconv" 7 | "strings" 8 | ) 9 | 10 | // Float parse from string 11 | func Float(str string) float64 { 12 | re := regexp.MustCompile(`\d+[.,]\d+`) 13 | f, err := strconv.ParseFloat(strings.Replace(re.FindString(str), ",", ".", 1), 64) 14 | if err != nil { 15 | return 0 16 | } 17 | return f 18 | } 19 | 20 | // ID parse return ID value from url 21 | func ID(path string) (id string) { 22 | p := strings.Split(path, "?") 23 | if len(p) == 2 { 24 | m, err := url.ParseQuery(p[1]) 25 | if err == nil { 26 | id = m.Get("id") 27 | } 28 | } 29 | return 30 | } 31 | 32 | // Int parse from string 33 | func Int(str string) int { 34 | re := regexp.MustCompile(`[^0-9 ]+`) 35 | i, err := strconv.Atoi(re.ReplaceAllString(str, "")) 36 | if err != nil { 37 | return 0 38 | } 39 | return i 40 | } 41 | 42 | // Int64 parse from string 43 | func Int64(str string) int64 { 44 | re := regexp.MustCompile(`[^0-9 ]+`) 45 | i64, err := strconv.ParseInt(re.ReplaceAllString(str, ""), 10, 64) 46 | if err != nil { 47 | return 0 48 | } 49 | return i64 50 | } 51 | -------------------------------------------------------------------------------- /internal/util/util.go: -------------------------------------------------------------------------------- 1 | package util 2 | 3 | import ( 4 | "bytes" 5 | "encoding/json" 6 | "fmt" 7 | "io/ioutil" 8 | "net/http" 9 | "net/url" 10 | "regexp" 11 | "strings" 12 | 13 | "github.com/k3a/html2text" 14 | "github.com/tidwall/gjson" 15 | ) 16 | 17 | var ( 18 | scriptRegex = regexp.MustCompile(`>AF_initDataCallback[\s\S]*?<\/script`) 19 | keyRegex = regexp.MustCompile(`(ds:\d*?)'`) 20 | valueRegex = regexp.MustCompile(`data:([\s\S]*?), sideChannel: {}}\);<\/`) 21 | ) 22 | 23 | // AbsoluteURL return absolute url 24 | func AbsoluteURL(base, path string) (string, error) { 25 | p, err := url.Parse(path) 26 | if err != nil { 27 | return "", err 28 | } 29 | b, err := url.Parse(base) 30 | if err != nil { 31 | return "", err 32 | } 33 | return b.ResolveReference(p).String(), nil 34 | } 35 | 36 | // BatchExecute for PlayStoreUi 37 | func BatchExecute(country, language, payload string) (string, error) { 38 | url := "https://play.google.com/_/PlayStoreUi/data/batchexecute" 39 | 40 | req, err := http.NewRequest("POST", url, strings.NewReader(payload)) 41 | if err != nil { 42 | return "", err 43 | } 44 | req.Header.Set("Content-Type", "application/x-www-form-urlencoded;charset=UTF-8") 45 | 46 | q := req.URL.Query() 47 | q.Add("authuser", "0") 48 | q.Add("bl", "boq_playuiserver_20190424.04_p0") 49 | q.Add("gl", country) 50 | q.Add("hl", language) 51 | q.Add("soc-app", "121") 52 | q.Add("soc-platform", "1") 53 | q.Add("soc-device", "1") 54 | q.Add("rpcids", "qnKhOb") 55 | req.URL.RawQuery = q.Encode() 56 | 57 | body, err := DoRequest(req) 58 | if err != nil { 59 | return "", err 60 | } 61 | 62 | var js [][]interface{} 63 | err = json.Unmarshal(bytes.TrimLeft(body, ")]}'"), &js) 64 | if err != nil { 65 | return "", err 66 | } 67 | if len(js) < 1 || len(js[0]) < 2 { 68 | return "", fmt.Errorf("invalid size of the resulting array") 69 | } 70 | if js[0][2] == nil { 71 | return "", nil 72 | } 73 | 74 | return js[0][2].(string), nil 75 | } 76 | 77 | // ExtractInitData from Google HTML 78 | func ExtractInitData(html []byte) map[string]string { 79 | data := make(map[string]string) 80 | scripts := scriptRegex.FindAll(html, -1) 81 | for _, script := range scripts { 82 | key := keyRegex.FindSubmatch(script) 83 | value := valueRegex.FindSubmatch(script) 84 | if len(key) > 1 && len(value) > 1 { 85 | data[string(key[1])] = string(value[1]) 86 | } 87 | } 88 | return data 89 | } 90 | 91 | // GetJSONArray by path 92 | func GetJSONArray(data string, paths ...string) []gjson.Result { 93 | for _, path := range paths { 94 | value := gjson.Get(data, path) 95 | if value.Exists() && value.Type != gjson.Null { 96 | return value.Array() 97 | } 98 | } 99 | return nil 100 | } 101 | 102 | // GetJSONValue with multiple path 103 | func GetJSONValue(data string, paths ...string) string { 104 | for _, path := range paths { 105 | value := gjson.Get(data, path) 106 | if value.Exists() && value.Type != gjson.Null { 107 | return value.String() 108 | } 109 | } 110 | return "" 111 | } 112 | 113 | // DoRequest by HTTP and read all 114 | func DoRequest(req *http.Request) ([]byte, error) { 115 | client := http.DefaultClient 116 | resp, err := client.Do(req) 117 | if err != nil { 118 | return nil, err 119 | } 120 | 121 | defer resp.Body.Close() 122 | 123 | if resp.StatusCode != http.StatusOK { 124 | return nil, fmt.Errorf("request error: %s", resp.Status) 125 | } 126 | 127 | return ioutil.ReadAll(resp.Body) 128 | } 129 | 130 | // GetInitData from Google HTML 131 | func GetInitData(req *http.Request) (map[string]string, error) { 132 | html, err := DoRequest(req) 133 | if err != nil { 134 | return nil, err 135 | } 136 | 137 | return ExtractInitData(html), nil 138 | } 139 | 140 | // HTMLToText return plain text from HTML 141 | func HTMLToText(html string) string { 142 | html2text.SetUnixLbr(true) 143 | return html2text.HTML2Text(html) 144 | } 145 | -------------------------------------------------------------------------------- /pkg/app/app.go: -------------------------------------------------------------------------------- 1 | package app 2 | 3 | import ( 4 | "fmt" 5 | "net/http" 6 | "strings" 7 | "time" 8 | 9 | "github.com/n0madic/google-play-scraper/internal/parse" 10 | "github.com/n0madic/google-play-scraper/internal/util" 11 | "github.com/n0madic/google-play-scraper/pkg/reviews" 12 | ) 13 | 14 | const ( 15 | detailURL = "https://play.google.com/store/apps/details?id=" 16 | playURL = "https://play.google.com" 17 | ) 18 | 19 | // Price of app 20 | type Price struct { 21 | Currency string 22 | Value float64 23 | } 24 | 25 | // App of search 26 | type App struct { 27 | AdSupported bool 28 | AndroidVersion string 29 | AndroidVersionMin float64 30 | Available bool 31 | ContentRating string 32 | ContentRatingDescription string 33 | Description string 34 | DescriptionHTML string 35 | Developer string 36 | DeveloperAddress string 37 | DeveloperEmail string 38 | DeveloperID string 39 | DeveloperInternalID string 40 | DeveloperURL string 41 | DeveloperWebsite string 42 | FamilyGenre string 43 | FamilyGenreID string 44 | Free bool 45 | Genre string 46 | GenreID string 47 | HeaderImage string 48 | IAPOffers bool 49 | IAPRange string 50 | Icon string 51 | ID string 52 | Installs string 53 | InstallsMin int 54 | InstallsMax int 55 | Permissions map[string][]string 56 | Price Price 57 | PriceFull Price 58 | PrivacyPolicy string 59 | Ratings int 60 | RatingsHistogram map[int]int 61 | RecentChanges string 62 | RecentChangesHTML string 63 | Released string 64 | Reviews []*reviews.Review 65 | ReviewsTotalCount int 66 | Score float64 67 | ScoreText string 68 | Screenshots []string 69 | SimilarURL string 70 | Summary string 71 | Title string 72 | Updated time.Time 73 | URL string 74 | Version string 75 | Video string 76 | VideoImage string 77 | options *Options 78 | } 79 | 80 | // Options of app 81 | type Options struct { 82 | Country string 83 | Language string 84 | } 85 | 86 | // LoadDetails of app 87 | func (app *App) LoadDetails() error { 88 | if app.URL == "" { 89 | if app.ID != "" { 90 | app.URL = detailURL + app.ID 91 | } else { 92 | return fmt.Errorf("App ID or URL required") 93 | } 94 | } 95 | 96 | req, err := http.NewRequest("GET", app.URL, nil) 97 | if err != nil { 98 | return err 99 | } 100 | 101 | q := req.URL.Query() 102 | q.Add("gl", app.options.Country) 103 | q.Add("hl", app.options.Language) 104 | req.URL.RawQuery = q.Encode() 105 | 106 | appData, err := util.GetInitData(req) 107 | if err != nil { 108 | return err 109 | } 110 | 111 | if app.ID == "" { 112 | app.ID = parse.ID(app.URL) 113 | } 114 | 115 | for dsAppInfo := range appData { 116 | relativeDevURL := util.GetJSONValue(appData[dsAppInfo], "1.2.68.1.4.2") 117 | if relativeDevURL == "" { 118 | continue 119 | } 120 | 121 | app.AdSupported = util.GetJSONValue(appData[dsAppInfo], "1.2.48") != "" 122 | 123 | app.AndroidVersion = util.GetJSONValue(appData[dsAppInfo], "1.2.140.1.1.0.0.1") 124 | app.AndroidVersionMin = parse.Float(app.AndroidVersion) 125 | 126 | app.Available = util.GetJSONValue(appData[dsAppInfo], "1.2.18.0") != "" 127 | 128 | app.ContentRating = util.GetJSONValue(appData[dsAppInfo], "1.2.9.0") 129 | app.ContentRatingDescription = util.GetJSONValue(appData[dsAppInfo], "1.2.9.2.1") 130 | 131 | app.DescriptionHTML = util.GetJSONValue(appData[dsAppInfo], "1.2.72.0.1") 132 | app.Description = util.HTMLToText(app.DescriptionHTML) 133 | 134 | devURL, _ := util.AbsoluteURL(playURL, relativeDevURL) 135 | app.Developer = util.GetJSONValue(appData[dsAppInfo], "1.2.68.0") 136 | app.DeveloperAddress = util.GetJSONValue(appData[dsAppInfo], "1.2.69.2.0") 137 | app.DeveloperEmail = util.GetJSONValue(appData[dsAppInfo], "1.2.69.1.0") 138 | app.DeveloperID = parse.ID(util.GetJSONValue(appData[dsAppInfo], "1.2.68.1.4.2")) 139 | app.DeveloperInternalID = util.GetJSONValue(appData[dsAppInfo], "1.2.68.2") 140 | app.DeveloperURL = devURL 141 | app.DeveloperWebsite = util.GetJSONValue(appData[dsAppInfo], "1.2.69.0.5.2") 142 | 143 | app.Genre = util.GetJSONValue(appData[dsAppInfo], "1.2.79.0.0.0") 144 | app.GenreID = util.GetJSONValue(appData[dsAppInfo], "1.2.79.0.0.2") 145 | app.FamilyGenre = util.GetJSONValue(appData[dsAppInfo], "1.12.13.1.0") 146 | app.FamilyGenreID = util.GetJSONValue(appData[dsAppInfo], "1.12.13.1.2") 147 | 148 | app.HeaderImage = util.GetJSONValue(appData[dsAppInfo], "1.2.96.0.3.2") 149 | 150 | app.IAPRange = util.GetJSONValue(appData[dsAppInfo], "1.2.19.0") 151 | app.IAPOffers = app.IAPRange != "" 152 | 153 | app.Icon = util.GetJSONValue(appData[dsAppInfo], "1.2.95.0.3.2") 154 | 155 | app.Installs = util.GetJSONValue(appData[dsAppInfo], "1.2.13.0") 156 | app.InstallsMin = parse.Int(util.GetJSONValue(appData[dsAppInfo], "1.2.13.1")) 157 | app.InstallsMax = parse.Int(util.GetJSONValue(appData[dsAppInfo], "1.2.13.2")) 158 | 159 | price := Price{ 160 | Currency: util.GetJSONValue(appData[dsAppInfo], "1.2.57.0.0.0.0.1.0.1"), 161 | Value: parse.Float(util.GetJSONValue(appData[dsAppInfo], "1.2.57.0.0.0.0.1.0.2")), 162 | } 163 | app.Free = price.Value == 0 164 | app.Price = price 165 | app.PriceFull = Price{ 166 | Currency: util.GetJSONValue(appData[dsAppInfo], "1.2.57.0.0.0.0.1.1.1"), 167 | Value: parse.Float(util.GetJSONValue(appData[dsAppInfo], "1.2.57.0.0.0.0.1.1.2")), 168 | } 169 | 170 | app.PrivacyPolicy = util.GetJSONValue(appData[dsAppInfo], "1.2.99.0.5.2") 171 | 172 | app.Ratings = parse.Int(util.GetJSONValue(appData[dsAppInfo], "1.2.51.2.1")) 173 | app.RatingsHistogram = map[int]int{ 174 | 1: parse.Int(util.GetJSONValue(appData[dsAppInfo], "1.2.51.1.1.1")), 175 | 2: parse.Int(util.GetJSONValue(appData[dsAppInfo], "1.2.51.1.2.1")), 176 | 3: parse.Int(util.GetJSONValue(appData[dsAppInfo], "1.2.51.1.3.1")), 177 | 4: parse.Int(util.GetJSONValue(appData[dsAppInfo], "1.2.51.1.4.1")), 178 | 5: parse.Int(util.GetJSONValue(appData[dsAppInfo], "1.2.51.1.5.1")), 179 | } 180 | 181 | for dsAppReview := range appData { 182 | reviewList := util.GetJSONArray(appData[dsAppReview], "0") 183 | check := util.GetJSONValue(appData[dsAppReview], "2.0.1.2.0") 184 | if len(reviewList) > 2 && check != "" { 185 | for _, review := range reviewList { 186 | r := reviews.Parse(review.String()) 187 | if r != nil { 188 | app.Reviews = append(app.Reviews, r) 189 | } 190 | } 191 | break 192 | } 193 | } 194 | app.ReviewsTotalCount = parse.Int(util.GetJSONValue(appData[dsAppInfo], "1.2.51.2.1")) 195 | 196 | screenshots := util.GetJSONArray(appData[dsAppInfo], "1.2.78.0") 197 | for _, screen := range screenshots { 198 | app.Screenshots = append(app.Screenshots, util.GetJSONValue(screen.String(), "3.2")) 199 | } 200 | 201 | for dsAppSimilar := range appData { 202 | similarURL := util.GetJSONValue(appData[dsAppSimilar], "1.1.1.21.1.2.4.2") 203 | if similarURL != "" { 204 | app.SimilarURL, _ = util.AbsoluteURL(playURL, similarURL) 205 | break 206 | } 207 | } 208 | 209 | app.RecentChangesHTML = util.GetJSONValue(appData[dsAppInfo], "1.2.144.1.1", "1.2.145.0.0") 210 | app.RecentChanges = util.HTMLToText(app.RecentChangesHTML) 211 | app.Released = util.GetJSONValue(appData[dsAppInfo], "1.2.10.0") 212 | app.Score = parse.Float(util.GetJSONValue(appData[dsAppInfo], "1.2.51.0.1")) 213 | app.ScoreText = util.GetJSONValue(appData[dsAppInfo], "1.2.51.0.0") 214 | app.Summary = util.GetJSONValue(appData[dsAppInfo], "1.2.73.0.1") 215 | app.Title = util.GetJSONValue(appData[dsAppInfo], "1.2.0.0") 216 | app.Updated = time.Unix(parse.Int64(util.GetJSONValue(appData[dsAppInfo], "1.2.145.0.1.0")), 0) 217 | app.Version = util.GetJSONValue(appData[dsAppInfo], "1.2.140.0.0.0") 218 | app.Video = util.GetJSONValue(appData[dsAppInfo], "1.2.100.0.0.3.2") 219 | app.VideoImage = util.GetJSONValue(appData[dsAppInfo], "1.2.100.1.0.3.2") 220 | } 221 | return nil 222 | } 223 | 224 | // LoadPermissions get the list of perms an app has access to 225 | func (app *App) LoadPermissions() error { 226 | payload := strings.Replace("f.req=%5B%5B%5B%22xdSrCf%22%2C%22%5B%5Bnull%2C%5B%5C%22{{appID}}%5C%22%2C7%5D%2C%5B%5D%5D%5D%22%2Cnull%2C%221%22%5D%5D%5D", "{{appID}}", app.ID, 1) 227 | 228 | js, err := util.BatchExecute(app.options.Country, app.options.Language, payload) 229 | if err != nil { 230 | return err 231 | } 232 | 233 | app.Permissions = make(map[string][]string) 234 | for _, perm := range util.GetJSONArray(js, "0") { 235 | key := util.GetJSONValue(perm.String(), "0") 236 | for _, permission := range util.GetJSONArray(perm.String(), "2") { 237 | app.Permissions[key] = append(app.Permissions[key], util.GetJSONValue(permission.String(), "1")) 238 | } 239 | } 240 | 241 | return nil 242 | } 243 | 244 | // New return App instance 245 | func New(id string, options Options) *App { 246 | return &App{ 247 | ID: id, 248 | URL: detailURL + id, 249 | options: &options, 250 | } 251 | } 252 | -------------------------------------------------------------------------------- /pkg/app/app_test.go: -------------------------------------------------------------------------------- 1 | package app 2 | 3 | import ( 4 | "net/url" 5 | "testing" 6 | ) 7 | 8 | func TestLoadDetails(t *testing.T) { 9 | app := New("com.nekki.vector.paid", Options{"us", "en"}) 10 | err := app.LoadDetails() 11 | if err != nil { 12 | t.Error(err) 13 | } 14 | 15 | if !app.AdSupported { 16 | t.Error("Expected AdSupported is true, got", app.AdSupported) 17 | } 18 | if app.AndroidVersion == "" { 19 | t.Error("Expected Android version") 20 | } 21 | if app.AndroidVersionMin == 0 { 22 | t.Error("Expected AndroidVersionMin is greater than zero") 23 | } 24 | if !app.Available { 25 | t.Error("Expected Available is true, got", app.Available) 26 | } 27 | if app.ContentRating == "" { 28 | t.Error("Expected ContentRating") 29 | } 30 | if app.Description == "" { 31 | t.Error("Expected Description") 32 | } 33 | if app.DescriptionHTML == "" { 34 | t.Error("Expected DescriptionHTML") 35 | } 36 | if app.Developer == "" { 37 | t.Error("Expected Developer") 38 | } 39 | if app.DeveloperAddress == "" { 40 | t.Error("Expected DeveloperAddress") 41 | } 42 | if app.DeveloperEmail == "" { 43 | t.Error("Expected DeveloperEmail") 44 | } 45 | if app.DeveloperID == "" { 46 | t.Error("Expected DeveloperID") 47 | } 48 | if app.DeveloperInternalID == "" { 49 | t.Error("Expected DeveloperInternalID") 50 | } 51 | if _, err = url.ParseRequestURI(app.DeveloperURL); err != nil { 52 | t.Error("Expected valid DeveloperURL, got", app.DeveloperURL) 53 | } 54 | if _, err = url.ParseRequestURI(app.DeveloperWebsite); err != nil { 55 | t.Error("Expected valid DeveloperWebsite, got", app.DeveloperWebsite) 56 | } 57 | // if app.FamilyGenre == "" { 58 | // t.Error("Expected FamilyGenre") 59 | // } 60 | // if app.FamilyGenreID == "" { 61 | // t.Error("Expected FamilyGenreID") 62 | // } 63 | if app.Genre == "" { 64 | t.Error("Expected Genre") 65 | } 66 | if app.GenreID == "" { 67 | t.Error("Expected GenreID") 68 | } 69 | if app.HeaderImage == "" { 70 | t.Error("Expected HeaderImage") 71 | } 72 | if !app.IAPOffers { 73 | t.Error("Expected IAPOffers is true, got", app.IAPOffers) 74 | } 75 | if app.IAPRange == "" { 76 | t.Error("Expected IAPRange") 77 | } 78 | if _, err = url.ParseRequestURI(app.Icon); err != nil { 79 | t.Error("Expected valid Icon url, got", app.Icon) 80 | } 81 | if app.ID == "" { 82 | t.Error("Expected ID") 83 | } 84 | if app.Installs == "" { 85 | t.Error("Expected Installs") 86 | } 87 | if app.InstallsMin == 0 { 88 | t.Error("Expected InstallsMin is greater than zero") 89 | } 90 | if app.InstallsMax == 0 { 91 | t.Error("Expected InstallsMax is greater than zero") 92 | } 93 | if app.Price.Currency == "" { 94 | t.Error("Expected Price.Currency") 95 | } 96 | if app.Price.Value == 0 { 97 | t.Error("Expected Price.Value is greater than zero") 98 | } 99 | if _, err = url.ParseRequestURI(app.Icon); err != nil { 100 | t.Error("Expected valid Icon url, got", app.Icon) 101 | } 102 | if app.PrivacyPolicy == "" { 103 | t.Error("Expected PrivacyPolicy") 104 | } 105 | if app.Ratings == 0 { 106 | t.Error("Expected Ratings is greater than zero") 107 | } 108 | if len(app.RatingsHistogram) != 5 { 109 | t.Error("Expected RatingsHistogram length if 5, got", len(app.RatingsHistogram)) 110 | } 111 | for i := 1; i <= 5; i++ { 112 | if val, ok := app.RatingsHistogram[i]; ok { 113 | if val == 0 { 114 | t.Errorf("Expected RatingsHistogram[%d] is greater than zero", i) 115 | } 116 | } else { 117 | t.Error("Expected RatingsHistogram with key", i) 118 | } 119 | } 120 | if app.RecentChanges == "" { 121 | t.Error("Expected RecentChanges") 122 | } 123 | if app.RecentChangesHTML == "" { 124 | t.Error("Expected RecentChangesHTML") 125 | } 126 | if app.Released == "" { 127 | t.Error("Expected Released date") 128 | } 129 | if len(app.Reviews) == 0 { 130 | t.Error("Expected Reviews length is greater than zero") 131 | } else { 132 | for i, comment := range app.Reviews { 133 | if comment.Text == "" { 134 | t.Errorf("Expected comment Text in Reviews[%d]: %+v", i, comment) 135 | } 136 | } 137 | } 138 | if app.ReviewsTotalCount == 0 { 139 | t.Error("Expected ReviewsTotalCount is greater than zero") 140 | } 141 | if app.Score == 0 { 142 | t.Error("Expected Score is greater than zero") 143 | } 144 | if app.ScoreText == "" { 145 | t.Error("Expected ScoreText") 146 | } 147 | if len(app.Screenshots) == 0 { 148 | t.Error("Expected Screenshots length is greater than zero") 149 | } else { 150 | for i, screen := range app.Screenshots { 151 | if _, err = url.ParseRequestURI(screen); err != nil { 152 | t.Errorf("Expected valid Screenshots[%d] url, got %s", i, screen) 153 | } 154 | } 155 | } 156 | if _, err = url.ParseRequestURI(app.SimilarURL); err != nil { 157 | t.Error("Expected valid SimilarURL, got", app.SimilarURL) 158 | } 159 | if app.Summary == "" { 160 | t.Error("Expected Summary") 161 | } 162 | if app.Title == "" { 163 | t.Error("Expected Title") 164 | } 165 | if app.Updated.IsZero() { 166 | t.Error("Expected Updated date") 167 | } 168 | if _, err = url.ParseRequestURI(app.URL); err != nil { 169 | t.Error("Expected valid URL, got", app.URL) 170 | } 171 | if app.Version == "" { 172 | t.Error("Expected Version") 173 | } 174 | if _, err = url.ParseRequestURI(app.Video); err != nil { 175 | t.Error("Expected valid Video url, got", app.Video) 176 | } 177 | if _, err = url.ParseRequestURI(app.VideoImage); err != nil { 178 | t.Error("Expected valid VideoImage url, got", app.VideoImage) 179 | } 180 | } 181 | 182 | func TestLoadPermissions(t *testing.T) { 183 | app := New("com.android.chrome", Options{"us", "us"}) 184 | err := app.LoadPermissions() 185 | if err != nil { 186 | t.Error(err) 187 | } 188 | 189 | if len(app.Permissions) == 0 { 190 | t.Fatal("Expected Permissions map length is greater than zero") 191 | } 192 | 193 | for key, permission := range app.Permissions { 194 | if key == "" { 195 | t.Error("Expected permission key is not empty") 196 | } 197 | 198 | if len(permission) == 0 { 199 | t.Fatal("Expected permission list length is greater than zero") 200 | } 201 | 202 | for _, perm := range permission { 203 | if perm == "" { 204 | t.Error("Expected permission in the list is not empty") 205 | } 206 | } 207 | 208 | } 209 | } 210 | -------------------------------------------------------------------------------- /pkg/category/category.go: -------------------------------------------------------------------------------- 1 | package category 2 | 3 | import ( 4 | "net/http" 5 | 6 | "github.com/n0madic/google-play-scraper/internal/util" 7 | "github.com/n0madic/google-play-scraper/pkg/scraper" 8 | "github.com/n0madic/google-play-scraper/pkg/store" 9 | ) 10 | 11 | // Options type alias 12 | type Options = scraper.Options 13 | 14 | // List of clusters 15 | type List map[string]*scraper.Scraper 16 | 17 | // New return category list instance 18 | func New(category store.Category, age store.Age, options Options) (List, error) { 19 | path := "" 20 | if category != "" { 21 | path += "/category/" + string(category) 22 | } 23 | 24 | req, err := http.NewRequest("GET", scraper.BaseURL+path, nil) 25 | if err != nil { 26 | return nil, err 27 | } 28 | 29 | if age != "" { 30 | q := req.URL.Query() 31 | q.Add("age", string(age)) 32 | req.URL.RawQuery = q.Encode() 33 | } 34 | 35 | data, err := util.GetInitData(req) 36 | if err != nil { 37 | return nil, err 38 | } 39 | 40 | list := make(List) 41 | 42 | clusterList := util.GetJSONArray(data["ds:3"], "0.1") 43 | for _, cluster := range clusterList { 44 | key := util.GetJSONValue(cluster.String(), "20.0", "21.1.0", "22.1.0") 45 | url, err := util.AbsoluteURL(scraper.BaseURL, util.GetJSONValue(cluster.String(), "20.2.4.2", "21.1.2.4.2", "22.1.2.4.2")) 46 | if key != "" && err == nil { 47 | list[key] = scraper.New(url, &options) 48 | list[key].ParseResult(cluster.String(), "21.0", "22.0") 49 | } 50 | } 51 | 52 | return list, nil 53 | } 54 | -------------------------------------------------------------------------------- /pkg/category/category_test.go: -------------------------------------------------------------------------------- 1 | package category 2 | 3 | import ( 4 | "testing" 5 | 6 | "github.com/n0madic/google-play-scraper/pkg/store" 7 | ) 8 | 9 | var resultsCount = 10 10 | 11 | func TestCategory(t *testing.T) { 12 | l, err := New(store.Game, store.AgeFiveUnder, Options{ 13 | Country: "us", 14 | Language: "us", 15 | Number: resultsCount, 16 | }) 17 | if err != nil { 18 | t.Error(err) 19 | } 20 | 21 | if len(l) < 1 { 22 | t.Errorf("No empty clusters expected") 23 | } else { 24 | for key, cluster := range l { 25 | err := cluster.Run() 26 | if err != nil { 27 | t.Error(err) 28 | } 29 | 30 | if len(cluster.Results) == 0 { 31 | t.Errorf("[%s] Expected non-zero Results length", key) 32 | } 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /pkg/collection/collection.go: -------------------------------------------------------------------------------- 1 | package collection 2 | 3 | import ( 4 | "github.com/n0madic/google-play-scraper/pkg/scraper" 5 | "github.com/n0madic/google-play-scraper/pkg/store" 6 | ) 7 | 8 | // Options type alias 9 | type Options = scraper.Options 10 | 11 | // New return collection list instance 12 | func New(collection store.Collection, options Options) *scraper.Scraper { 13 | return scraper.New(scraper.BaseURL+"/collection/"+string(collection), &options) 14 | } 15 | -------------------------------------------------------------------------------- /pkg/collection/collection_test.go: -------------------------------------------------------------------------------- 1 | package collection 2 | 3 | import ( 4 | "testing" 5 | 6 | "github.com/n0madic/google-play-scraper/pkg/store" 7 | ) 8 | 9 | var resultsCount = 70 10 | 11 | func TestCollection(t *testing.T) { 12 | q := New(store.TopPaid, Options{ 13 | Country: "us", 14 | Language: "us", 15 | Number: resultsCount, 16 | }) 17 | err := q.Run() 18 | if err != nil { 19 | t.Error(err) 20 | } 21 | 22 | if len(q.Results) != resultsCount { 23 | t.Errorf("Expected Results length is %d, got %d", resultsCount, len(q.Results)) 24 | } 25 | 26 | for _, app := range q.Results { 27 | if app.Title == "" { 28 | t.Error("Expected Title is greater than zero") 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /pkg/developer/developer.go: -------------------------------------------------------------------------------- 1 | package developer 2 | 3 | import ( 4 | "net/url" 5 | 6 | "github.com/n0madic/google-play-scraper/pkg/scraper" 7 | ) 8 | 9 | // Options type alias 10 | type Options = scraper.Options 11 | 12 | // New return the list of applications by the given developer name 13 | func New(name string, options Options) *scraper.Scraper { 14 | return new("/developer", name, &options) 15 | } 16 | 17 | // NewByID return the list of applications by the given developer ID 18 | func NewByID(devID string, options Options) *scraper.Scraper { 19 | return new("/dev", devID, &options) 20 | } 21 | 22 | func new(path, name string, options *Options) *scraper.Scraper { 23 | u, err := url.Parse(scraper.BaseURL + path) 24 | if err != nil { 25 | return nil 26 | } 27 | q := u.Query() 28 | q.Set("id", name) 29 | u.RawQuery = q.Encode() 30 | return scraper.New(u.String(), options) 31 | } 32 | -------------------------------------------------------------------------------- /pkg/developer/developer_test.go: -------------------------------------------------------------------------------- 1 | package developer 2 | 3 | import ( 4 | "testing" 5 | ) 6 | 7 | var resultsCount = 47 8 | 9 | func TestDeveloper(t *testing.T) { 10 | q := New("Google LLC", Options{ 11 | Number: resultsCount, 12 | }) 13 | err := q.Run() 14 | if err != nil { 15 | t.Error(err) 16 | } 17 | 18 | if len(q.Results) != resultsCount { 19 | t.Errorf("Expected Results length is %d, got %d", resultsCount, len(q.Results)) 20 | } 21 | } 22 | 23 | func TestDeveloperByID(t *testing.T) { 24 | // Test on Google LLC 25 | q := NewByID("5700313618786177705", Options{ 26 | Number: resultsCount, 27 | }) 28 | err := q.Run() 29 | if err != nil { 30 | t.Error(err) 31 | } 32 | 33 | if len(q.Results) != resultsCount { 34 | t.Errorf("Expected Results length is %d, got %d", resultsCount, len(q.Results)) 35 | } 36 | for _, app := range q.Results { 37 | if app.URL == "" { 38 | t.Error("Expected App.URL is not empty, but was empty") 39 | } 40 | } 41 | for _, app := range q.Results { 42 | if app.Title == "" { 43 | t.Error("Expected App.Title is not empty, but was empty") 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /pkg/reviews/results.go: -------------------------------------------------------------------------------- 1 | package reviews 2 | 3 | // Results of operation 4 | type Results []*Review 5 | 6 | // Append result 7 | func (results *Results) Append(res ...Review) { 8 | for _, result := range res { 9 | if !results.searchDuplicate(result.ID) { 10 | results.append(result) 11 | } 12 | } 13 | } 14 | 15 | func (results *Results) append(result Review) { 16 | *results = append(*results, &result) 17 | } 18 | 19 | func (results *Results) searchDuplicate(id string) bool { 20 | for _, result := range *results { 21 | if id == result.ID { 22 | return true 23 | } 24 | } 25 | return false 26 | } 27 | -------------------------------------------------------------------------------- /pkg/reviews/reviews.go: -------------------------------------------------------------------------------- 1 | package reviews 2 | 3 | import ( 4 | "fmt" 5 | "strconv" 6 | "strings" 7 | "time" 8 | 9 | "github.com/n0madic/google-play-scraper/internal/parse" 10 | "github.com/n0madic/google-play-scraper/internal/util" 11 | "github.com/n0madic/google-play-scraper/pkg/store" 12 | ) 13 | 14 | const ( 15 | initialRequest = `f.req=%5B%5B%5B%22UsvDTd%22%2C%22%5Bnull%2Cnull%2C%5B2%2C{{sort}}%2C%5B{{numberOfReviewsPerRequest}}%2Cnull%2Cnull%5D%2Cnull%2C%5B%5D%5D%2C%5B%5C%22{{appId}}%5C%22%2C7%5D%5D%22%2Cnull%2C%22generic%22%5D%5D%5D` 16 | paginatedRequest = `f.req=%5B%5B%5B%22UsvDTd%22%2C%22%5Bnull%2Cnull%2C%5B2%2C{{sort}}%2C%5B{{numberOfReviewsPerRequest}}%2Cnull%2C%5C%22{{withToken}}%5C%22%5D%2Cnull%2C%5B%5D%5D%2C%5B%5C%22{{appId}}%5C%22%2C7%5D%5D%22%2Cnull%2C%22generic%22%5D%5D%5D` 17 | ) 18 | 19 | var ErrTokenIsEmpty = fmt.Errorf("Token is empty") 20 | 21 | const maxPageSize = 40 22 | 23 | // Options of reviews 24 | type Options struct { 25 | Country string 26 | Language string 27 | Number int 28 | Sorting store.Sort 29 | } 30 | 31 | // Review of app 32 | type Review struct { 33 | Avatar string 34 | Criteria map[string]int64 35 | ID string 36 | Score int 37 | Reviewer string 38 | Reply string 39 | ReplyTimestamp time.Time 40 | Respondent string 41 | Text string 42 | Timestamp time.Time 43 | Useful int 44 | Version string 45 | } 46 | 47 | // URL of review 48 | func (r *Review) URL(appID string) string { 49 | if r.ID != "" { 50 | return fmt.Sprintf("https://play.google.com/store/apps/details?id=%s&reviewId=%s", appID, r.ID) 51 | } 52 | return "" 53 | } 54 | 55 | // Reviews instance 56 | type Reviews struct { 57 | appID string 58 | options *Options 59 | Results Results 60 | } 61 | 62 | // New return similar list instance 63 | func New(appID string, options Options) *Reviews { 64 | if options.Number == 0 { 65 | options.Number = maxPageSize 66 | } 67 | if options.Sorting == 0 { 68 | options.Sorting = store.SortHelpfulness 69 | } 70 | return &Reviews{ 71 | appID: appID, 72 | options: &options, 73 | } 74 | } 75 | 76 | func (reviews *Reviews) batchexecute(payload string) ([]Review, string, error) { 77 | js, err := util.BatchExecute(reviews.options.Country, reviews.options.Language, payload) 78 | if err != nil { 79 | return nil, "", err 80 | } 81 | 82 | nextToken := util.GetJSONValue(js, "1.1") 83 | 84 | var results []Review 85 | rev := util.GetJSONArray(js, "0") 86 | for _, review := range rev { 87 | result := Parse(review.String()) 88 | if result != nil { 89 | results = append(results, *result) 90 | } 91 | } 92 | 93 | return results, nextToken, nil 94 | } 95 | 96 | // only load first page of reviews 97 | func (reviews *Reviews) LoadFirstPage() ([]Review, string, error) { 98 | numberOfReviewsPerRequest := maxPageSize 99 | if numberOfReviewsPerRequest > reviews.options.Number { 100 | numberOfReviewsPerRequest = reviews.options.Number 101 | } 102 | 103 | r := strings.NewReplacer("{{sort}}", strconv.Itoa(int(reviews.options.Sorting)), 104 | "{{numberOfReviewsPerRequest}}", strconv.Itoa(numberOfReviewsPerRequest), 105 | "{{appId}}", string(reviews.appID), 106 | ) 107 | payload := r.Replace(initialRequest) 108 | 109 | results, token, err := reviews.batchexecute(payload) 110 | return results, token, err 111 | } 112 | 113 | // continue loading next page 114 | func (reviews *Reviews) LoadNextPage(token string) (results []Review, newToken string, err error) { 115 | if len(token) == 0 { 116 | err = ErrTokenIsEmpty 117 | return 118 | } 119 | 120 | numberOfReviewsPerRequest := maxPageSize 121 | if numberOfReviewsPerRequest > reviews.options.Number { 122 | numberOfReviewsPerRequest = reviews.options.Number 123 | } 124 | 125 | r := strings.NewReplacer("{{sort}}", strconv.Itoa(int(reviews.options.Sorting)), 126 | "{{numberOfReviewsPerRequest}}", strconv.Itoa(numberOfReviewsPerRequest), 127 | "{{withToken}}", token, 128 | "{{appId}}", string(reviews.appID), 129 | ) 130 | payload := r.Replace(paginatedRequest) 131 | results, newToken, err = reviews.batchexecute(payload) 132 | return 133 | } 134 | 135 | // Run reviews scraping 136 | func (reviews *Reviews) Run() error { 137 | results, token, err := reviews.LoadFirstPage() 138 | if err != nil { 139 | return err 140 | } 141 | 142 | if len(results) > reviews.options.Number { 143 | reviews.Results.Append(results[:reviews.options.Number]...) 144 | } else { 145 | reviews.Results.Append(results...) 146 | } 147 | 148 | for len(reviews.Results) != reviews.options.Number && token != "" { 149 | results, token, err = reviews.LoadNextPage(token) 150 | 151 | if len(results) == 0 || err != nil { 152 | break 153 | } 154 | 155 | if len(reviews.Results)+len(results) > reviews.options.Number { 156 | reviews.Results.Append(results[:reviews.options.Number-len(reviews.Results)]...) 157 | } else { 158 | reviews.Results.Append(results...) 159 | } 160 | } 161 | return nil 162 | } 163 | 164 | // Parse app review 165 | func Parse(review string) *Review { 166 | text := util.GetJSONValue(review, "4") 167 | if text != "" { 168 | criteriaList := util.GetJSONArray(review, "12.0") 169 | criteria := make(map[string]int64, len(criteriaList)) 170 | for _, criterion := range criteriaList { 171 | var rating int64 172 | if len(criterion.Array()) > 2 { 173 | rating = criterion.Array()[2].Array()[0].Int() 174 | } 175 | criteria[criterion.Array()[0].String()] = rating 176 | } 177 | return &Review{ 178 | Avatar: util.GetJSONValue(review, "1.1.3.2"), 179 | Criteria: criteria, 180 | ID: util.GetJSONValue(review, "0"), 181 | Reply: util.GetJSONValue(review, "7.1"), 182 | ReplyTimestamp: time.Unix(parse.Int64(util.GetJSONValue(review, "7.2.0")), 0), 183 | Respondent: util.GetJSONValue(review, "7.0"), 184 | Reviewer: util.GetJSONValue(review, "1.0"), 185 | Score: parse.Int(util.GetJSONValue(review, "2")), 186 | Text: text, 187 | Timestamp: time.Unix(parse.Int64(util.GetJSONValue(review, "5.0")), 0), 188 | Useful: parse.Int(util.GetJSONValue(review, "6")), 189 | Version: util.GetJSONValue(review, "10"), 190 | } 191 | } 192 | return nil 193 | } 194 | -------------------------------------------------------------------------------- /pkg/reviews/reviews_test.go: -------------------------------------------------------------------------------- 1 | package reviews 2 | 3 | import ( 4 | "testing" 5 | ) 6 | 7 | var resultsCount = 88 8 | 9 | func TestReviews(t *testing.T) { 10 | r := New("com.viber.voip", Options{ 11 | Number: resultsCount, 12 | }) 13 | err := r.Run() 14 | if err != nil { 15 | t.Error(err) 16 | } 17 | 18 | if len(r.Results) != resultsCount { 19 | t.Errorf("Expected Results length is %d, got %d", resultsCount, len(r.Results)) 20 | } else { 21 | for i, review := range r.Results { 22 | if review.Avatar == "" { 23 | t.Errorf("Expected reviewer Avatar in Results[%d]: %+v", i, review) 24 | } 25 | if review.ID == "" { 26 | t.Errorf("Expected review ID in Results[%d]: %+v", i, review) 27 | } 28 | if review.Reviewer == "" { 29 | t.Errorf("Expected Reviewer in Results[%d]: %+v", i, review) 30 | } 31 | if review.Score < 1 { 32 | t.Errorf("Expected Score is greater than zero in Results[%d]: %+v", i, review) 33 | } 34 | if review.Text == "" { 35 | t.Errorf("Expected review Text in Results[%d]: %+v", i, review) 36 | } 37 | if review.Timestamp.IsZero() { 38 | t.Errorf("Expected review Timestamp in Results[%d]: %+v", i, review) 39 | } 40 | if review.URL("") == "" { 41 | t.Errorf("Expected review URL in Results[%d]: %+v", i, review) 42 | } 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /pkg/scraper/results.go: -------------------------------------------------------------------------------- 1 | package scraper 2 | 3 | import "github.com/n0madic/google-play-scraper/pkg/app" 4 | 5 | // Results of operation 6 | type Results []*app.App 7 | 8 | // Append result 9 | func (results *Results) Append(res ...app.App) { 10 | for _, result := range res { 11 | if !results.searchDuplicate(result.ID) { 12 | results.append(result) 13 | } 14 | } 15 | } 16 | 17 | func (results *Results) append(result app.App) { 18 | *results = append(*results, &result) 19 | } 20 | 21 | func (results *Results) searchDuplicate(id string) bool { 22 | for _, result := range *results { 23 | if id == result.ID { 24 | return true 25 | } 26 | } 27 | return false 28 | } 29 | -------------------------------------------------------------------------------- /pkg/scraper/scraper.go: -------------------------------------------------------------------------------- 1 | package scraper 2 | 3 | import ( 4 | "net/http" 5 | "strings" 6 | "sync" 7 | 8 | "github.com/n0madic/google-play-scraper/internal/parse" 9 | "github.com/n0madic/google-play-scraper/internal/util" 10 | "github.com/n0madic/google-play-scraper/pkg/app" 11 | ) 12 | 13 | // BaseURL of Google Play Store 14 | const BaseURL = "https://play.google.com/store/apps" 15 | 16 | // Options of scraper 17 | type Options struct { 18 | Country string 19 | Discount bool 20 | Language string 21 | Number int 22 | PriceMin float64 23 | PriceMax float64 24 | ScoreMin float64 25 | ScoreMax float64 26 | } 27 | 28 | // Scraper instance 29 | type Scraper struct { 30 | options *Options 31 | Results Results 32 | url string 33 | } 34 | 35 | func (scraper *Scraper) initialRequest() ([]app.App, string, error) { 36 | req, err := http.NewRequest("GET", scraper.url, nil) 37 | if err != nil { 38 | return nil, "", err 39 | } 40 | q := req.URL.Query() 41 | q.Add("gl", scraper.options.Country) 42 | q.Add("hl", scraper.options.Language) 43 | req.URL.RawQuery = q.Encode() 44 | 45 | data, err := util.GetInitData(req) 46 | if err != nil { 47 | return nil, "", err 48 | } 49 | 50 | apps := scraper.parseResult(data["ds:3"], "0.1.0.22.0", "0.1.0.21.0") 51 | if len(apps) == 0 { 52 | apps = scraper.parseResult(data["ds:4"], "0.1.0.22.0", "0.1.0.21.0", "0.1.2.22.0", "0.1.3.22.0") 53 | } 54 | 55 | token := util.GetJSONValue(data["ds:3"], "0.1.0.22.1.3.1", "0.1.0.21.1.3.1") 56 | if token == "" { 57 | token = util.GetJSONValue(data["ds:4"], "0.1.2.22.1.3.1", "0.1.3.22.1.3.1") 58 | } 59 | 60 | // return results with next token 61 | return apps, token, nil 62 | } 63 | 64 | func (scraper *Scraper) batchexecute(token string) ([]app.App, string, error) { 65 | payload := strings.Replace("f.req=%5B%5B%5B%22qnKhOb%22%2C%22%5B%5Bnull%2C%5B%5B10%2C%5B10%2C50%5D%5D%2Ctrue%2Cnull%2C%5B96%2C27%2C4%2C8%2C57%2C30%2C110%2C79%2C11%2C16%2C49%2C1%2C3%2C9%2C12%2C104%2C55%2C56%2C51%2C10%2C34%2C77%5D%5D%2Cnull%2C%5C%22{{token}}%5C%22%5D%5D%22%2Cnull%2C%22generic%22%5D%5D%5D", "{{token}}", token, 1) 66 | 67 | js, err := util.BatchExecute(scraper.options.Country, scraper.options.Language, payload) 68 | if err != nil { 69 | return nil, "", err 70 | } 71 | 72 | nextToken := util.GetJSONValue(js, "0.0.7.1") 73 | return scraper.parseResult(js, "0.0.0"), nextToken, nil 74 | } 75 | 76 | // Run scraping 77 | func (scraper *Scraper) Run() error { 78 | scraper.Results = Results{} 79 | 80 | results, token, err := scraper.initialRequest() 81 | if err != nil { 82 | return err 83 | } 84 | 85 | if len(results) > scraper.options.Number { 86 | scraper.Results.Append(results[:scraper.options.Number]...) 87 | } else { 88 | scraper.Results.Append(results...) 89 | } 90 | 91 | for len(scraper.Results) != scraper.options.Number { 92 | results, token, err = scraper.batchexecute(token) 93 | 94 | if len(results) == 0 || err != nil { 95 | break 96 | } 97 | 98 | if len(scraper.Results)+len(results) > scraper.options.Number { 99 | scraper.Results.Append(results[:scraper.options.Number-len(scraper.Results)]...) 100 | } else { 101 | scraper.Results.Append(results...) 102 | } 103 | } 104 | 105 | return nil 106 | } 107 | 108 | // LoadMoreDetails for all results (in concurrency) 109 | func (scraper *Scraper) LoadMoreDetails(maxWorkers int) (errors []error) { 110 | if maxWorkers < 1 { 111 | maxWorkers = 10 112 | } 113 | semaphore := make(chan struct{}, maxWorkers) 114 | 115 | mutex := &sync.Mutex{} 116 | var wg sync.WaitGroup 117 | 118 | for _, result := range scraper.Results { 119 | semaphore <- struct{}{} 120 | wg.Add(1) 121 | go func(result *app.App) { 122 | defer wg.Done() 123 | err := result.LoadDetails() 124 | if err != nil { 125 | mutex.Lock() 126 | errors = append(errors, err) 127 | mutex.Unlock() 128 | } 129 | <-semaphore 130 | }(result) 131 | } 132 | wg.Wait() 133 | 134 | return 135 | } 136 | 137 | func (scraper *Scraper) parseResult(data string, paths ...string) (results []app.App) { 138 | for _, path := range paths { 139 | appData := util.GetJSONArray(data, path) 140 | for _, ap := range appData { 141 | price := app.Price{ 142 | Currency: util.GetJSONValue(ap.String(), "0.8.1.0.1", "8.1.0.1", "7.0.3.2.1.0.1"), 143 | Value: parse.Float(util.GetJSONValue(ap.String(), "0.8.1.0.2", "8.1.0.2", "7.0.3.2.1.0.2")), 144 | } 145 | if price.Value < scraper.options.PriceMin || 146 | (scraper.options.PriceMax > scraper.options.PriceMin && price.Value > scraper.options.PriceMax) { 147 | continue 148 | } 149 | 150 | priceFull := app.Price{ 151 | Currency: util.GetJSONValue(ap.String(), "0.8.1.0.1", "8.1.0.1", "7.0.3.2.1.1.1"), 152 | Value: parse.Float(util.GetJSONValue(ap.String(), "0.8.1.0.0", "8.1.0.0", "7.0.3.2.1.1.2")), 153 | } 154 | if scraper.options.Discount && priceFull.Value < price.Value { 155 | continue 156 | } 157 | 158 | score := parse.Float(util.GetJSONValue(ap.String(), "0.4.0", "4.0", "6.0.2.1.1")) 159 | if score < scraper.options.ScoreMin || 160 | (scraper.options.ScoreMax > scraper.options.ScoreMin && score > scraper.options.ScoreMax) { 161 | continue 162 | } 163 | 164 | application := app.New(util.GetJSONValue(ap.String(), "0.0.0", "0.0", "12.0"), app.Options{ 165 | Country: scraper.options.Country, 166 | Language: scraper.options.Language, 167 | }) 168 | 169 | application.DeveloperURL, _ = util.AbsoluteURL(scraper.url, util.GetJSONValue(ap.String(), "4.0.0.1.4.2")) 170 | application.Developer = util.GetJSONValue(ap.String(), "0.14", "14", "4.0.0.0") 171 | application.DeveloperID = parse.ID(application.DeveloperURL) 172 | application.Free = price.Value == 0 173 | application.Icon = util.GetJSONValue(ap.String(), "0.1.3.2", "1.3.2", "1.1.0.3.2") 174 | application.Price = price 175 | application.PriceFull = priceFull 176 | application.Score = score 177 | application.Summary = util.GetJSONValue(ap.String(), "0.13.1", "13.1", "4.1.1.1.1") 178 | application.Title = util.GetJSONValue(ap.String(), "0.3", "3", "2") 179 | application.URL, _ = util.AbsoluteURL(scraper.url, util.GetJSONValue(ap.String(), "0.10.4.2", "10.4.2", "9.4.2")) 180 | results = append(results, *application) 181 | } 182 | } 183 | return results 184 | } 185 | 186 | func (scraper *Scraper) ParseResult(data string, paths ...string) { 187 | scraper.Results.Append(scraper.parseResult(data, paths...)...) 188 | } 189 | 190 | // New return new Scraper instance 191 | func New(url string, options *Options) *Scraper { 192 | scraper := &Scraper{ 193 | Results: Results{}, 194 | options: options, 195 | url: url, 196 | } 197 | if scraper.options.Number == 0 { 198 | scraper.options.Number = 50 199 | } 200 | return scraper 201 | } 202 | -------------------------------------------------------------------------------- /pkg/search/search.go: -------------------------------------------------------------------------------- 1 | package search 2 | 3 | import ( 4 | "net/url" 5 | "strconv" 6 | 7 | "github.com/n0madic/google-play-scraper/pkg/scraper" 8 | ) 9 | 10 | const ( 11 | searchURL = "https://play.google.com/store/search" 12 | ) 13 | 14 | // PriceQuery value 15 | type PriceQuery int 16 | 17 | // Options type alias 18 | type Options = scraper.Options 19 | 20 | const ( 21 | // PriceAll - all prices 22 | PriceAll PriceQuery = iota 23 | // PriceFree - only free 24 | PriceFree 25 | // PricePaid - only paid 26 | PricePaid 27 | ) 28 | 29 | // NewQuery return Query instance 30 | func NewQuery(query string, price PriceQuery, options Options) *scraper.Scraper { 31 | baseURL, err := url.Parse(searchURL) 32 | if err != nil { 33 | return nil 34 | } 35 | 36 | // Query params 37 | params := url.Values{} 38 | params.Add("q", url.QueryEscape(query)) 39 | params.Add("c", "apps") 40 | params.Add("fpr", "false") 41 | params.Add("price", strconv.Itoa(int(price))) 42 | baseURL.RawQuery = params.Encode() 43 | 44 | return scraper.New(baseURL.String(), &options) 45 | } 46 | -------------------------------------------------------------------------------- /pkg/search/search_test.go: -------------------------------------------------------------------------------- 1 | package search 2 | 3 | import ( 4 | "testing" 5 | ) 6 | 7 | var resultsCount = 20 8 | 9 | func TestSearch(t *testing.T) { 10 | q := NewQuery("match", PriceAll, Options{ 11 | Country: "uk", 12 | Language: "en", 13 | Number: resultsCount, 14 | }) 15 | err := q.Run() 16 | if err != nil { 17 | t.Error(err) 18 | } 19 | 20 | if len(q.Results) != resultsCount { 21 | t.Errorf("Expected Results length is %d, got %d", resultsCount, len(q.Results)) 22 | } 23 | 24 | errors := q.LoadMoreDetails(0) 25 | for err := range errors { 26 | t.Error(err) 27 | } 28 | 29 | dupCheck := map[string]bool{} 30 | 31 | for _, result := range q.Results { 32 | if result.Description == "" { 33 | t.Error("Expected Description", result.ID) 34 | } 35 | if _, exist := dupCheck[result.ID]; exist { 36 | t.Errorf("Duplicate ID %s found in results", result.ID) 37 | } else { 38 | dupCheck[result.ID] = true 39 | } 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /pkg/similar/similar.go: -------------------------------------------------------------------------------- 1 | package similar 2 | 3 | import ( 4 | "github.com/n0madic/google-play-scraper/pkg/app" 5 | "github.com/n0madic/google-play-scraper/pkg/scraper" 6 | ) 7 | 8 | // Options type alias 9 | type Options = scraper.Options 10 | 11 | // New return similar list instance 12 | func New(appID string, options Options) *scraper.Scraper { 13 | a := app.New(appID, app.Options{ 14 | Country: options.Country, 15 | Language: options.Language, 16 | }) 17 | err := a.LoadDetails() 18 | if err != nil || a.SimilarURL == "" { 19 | return nil 20 | } 21 | return scraper.New(a.SimilarURL, &options) 22 | } 23 | -------------------------------------------------------------------------------- /pkg/similar/similar_test.go: -------------------------------------------------------------------------------- 1 | package similar 2 | 3 | import ( 4 | "testing" 5 | ) 6 | 7 | var resultsCount = 100 8 | 9 | func TestSimilar(t *testing.T) { 10 | q := New("com.google.android.googlequicksearchbox", Options{ 11 | Country: "us", 12 | Language: "us", 13 | Number: resultsCount, 14 | }) 15 | err := q.Run() 16 | if err != nil { 17 | t.Error(err) 18 | } 19 | 20 | if len(q.Results) == 0 { 21 | t.Errorf("Expected Results length is greater than zero") 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /pkg/store/age.go: -------------------------------------------------------------------------------- 1 | package store 2 | 3 | // Age range of apps 4 | type Age string 5 | 6 | const ( 7 | // AgeFiveUnder range (5-) 8 | AgeFiveUnder Age = "AGE_RANGE1" 9 | // AgeSixEight range (6-8) 10 | AgeSixEight Age = "AGE_RANGE2" 11 | // AgeNineUp range (9+) 12 | AgeNineUp Age = "AGE_RANGE3" 13 | ) 14 | -------------------------------------------------------------------------------- /pkg/store/category.go: -------------------------------------------------------------------------------- 1 | package store 2 | 3 | // Category of apps 4 | type Category string 5 | 6 | const ( 7 | // AndroidWear category of apps 8 | AndroidWear Category = "ANDROID_WEAR" 9 | // Application category of apps 10 | Application Category = "APPLICATION" 11 | // ArtAndDesign category of apps 12 | ArtAndDesign Category = "ART_AND_DESIGN" 13 | // AutoAndVehicles category of apps 14 | AutoAndVehicles Category = "AUTO_AND_VEHICLES" 15 | // Beauty category of apps 16 | Beauty Category = "BEAUTY" 17 | // BooksAndReference category of apps 18 | BooksAndReference Category = "BOOKS_AND_REFERENCE" 19 | // Business category of apps 20 | Business Category = "BUSINESS" 21 | // Comics category of apps 22 | Comics Category = "COMICS" 23 | // Communication category of apps 24 | Communication Category = "COMMUNICATION" 25 | // Dating category of apps 26 | Dating Category = "DATING" 27 | // Education category of apps 28 | Education Category = "EDUCATION" 29 | // Entertainment category of apps 30 | Entertainment Category = "ENTERTAINMENT" 31 | // Events category of apps 32 | Events Category = "EVENTS" 33 | // Family category of apps 34 | Family Category = "FAMILY" 35 | // FamilyAction category of apps 36 | FamilyAction Category = "FAMILY_ACTION" 37 | // FamilyBraingames category of apps 38 | FamilyBraingames Category = "FAMILY_BRAINGAMES" 39 | // FamilyCreate category of apps 40 | FamilyCreate Category = "FAMILY_CREATE" 41 | // FamilyEducation category of apps 42 | FamilyEducation Category = "FAMILY_EDUCATION" 43 | // FamilyMusicvideo category of apps 44 | FamilyMusicvideo Category = "FAMILY_MUSICVIDEO" 45 | // FamilyPretend category of apps 46 | FamilyPretend Category = "FAMILY_PRETEND" 47 | // Finance category of apps 48 | Finance Category = "FINANCE" 49 | // FoodAndDrink category of apps 50 | FoodAndDrink Category = "FOOD_AND_DRINK" 51 | // Game category of apps 52 | Game Category = "GAME" 53 | // GameAction category of apps 54 | GameAction Category = "GAME_ACTION" 55 | // GameAdventure category of apps 56 | GameAdventure Category = "GAME_ADVENTURE" 57 | // GameArcade category of apps 58 | GameArcade Category = "GAME_ARCADE" 59 | // GameBoard category of apps 60 | GameBoard Category = "GAME_BOARD" 61 | // GameCard category of apps 62 | GameCard Category = "GAME_CARD" 63 | // GameCasino category of apps 64 | GameCasino Category = "GAME_CASINO" 65 | // GameCasual category of apps 66 | GameCasual Category = "GAME_CASUAL" 67 | // GameEducational category of apps 68 | GameEducational Category = "GAME_EDUCATIONAL" 69 | // GameMusic category of apps 70 | GameMusic Category = "GAME_MUSIC" 71 | // GamePuzzle category of apps 72 | GamePuzzle Category = "GAME_PUZZLE" 73 | // GameRacing category of apps 74 | GameRacing Category = "GAME_RACING" 75 | // GameRolePlaying category of apps 76 | GameRolePlaying Category = "GAME_ROLE_PLAYING" 77 | // GameSimulation category of apps 78 | GameSimulation Category = "GAME_SIMULATION" 79 | // GameSports category of apps 80 | GameSports Category = "GAME_SPORTS" 81 | // GameStrategy category of apps 82 | GameStrategy Category = "GAME_STRATEGY" 83 | // GameTrivia category of apps 84 | GameTrivia Category = "GAME_TRIVIA" 85 | // GameWord category of apps 86 | GameWord Category = "GAME_WORD" 87 | // HealthAndFitness category of apps 88 | HealthAndFitness Category = "HEALTH_AND_FITNESS" 89 | // HouseAndHome category of apps 90 | HouseAndHome Category = "HOUSE_AND_HOME" 91 | // LibrariesAndDemo category of apps 92 | LibrariesAndDemo Category = "LIBRARIES_AND_DEMO" 93 | // Lifestyle category of apps 94 | Lifestyle Category = "LIFESTYLE" 95 | // MapsAndNavigation category of apps 96 | MapsAndNavigation Category = "MAPS_AND_NAVIGATION" 97 | // Medical category of apps 98 | Medical Category = "MEDICAL" 99 | // MusicAndAudio category of apps 100 | MusicAndAudio Category = "MUSIC_AND_AUDIO" 101 | // NewsAndMagazines category of apps 102 | NewsAndMagazines Category = "NEWS_AND_MAGAZINES" 103 | // Parenting category of apps 104 | Parenting Category = "PARENTING" 105 | // Personalization category of apps 106 | Personalization Category = "PERSONALIZATION" 107 | // Photography category of apps 108 | Photography Category = "PHOTOGRAPHY" 109 | // Productivity category of apps 110 | Productivity Category = "PRODUCTIVITY" 111 | // Shopping category of apps 112 | Shopping Category = "SHOPPING" 113 | // Social category of apps 114 | Social Category = "SOCIAL" 115 | // Sports category of apps 116 | Sports Category = "SPORTS" 117 | // Tools category of apps 118 | Tools Category = "TOOLS" 119 | // TravelAndLocal category of apps 120 | TravelAndLocal Category = "TRAVEL_AND_LOCAL" 121 | // VideoPlayers category of apps 122 | VideoPlayers Category = "VIDEO_PLAYERS" 123 | // WatchFace category of apps 124 | WatchFace Category = "WATCH_FACE" 125 | // Weather category of apps 126 | Weather Category = "WEATHER" 127 | ) 128 | -------------------------------------------------------------------------------- /pkg/store/collections.go: -------------------------------------------------------------------------------- 1 | package store 2 | 3 | // Collection of apps 4 | type Collection string 5 | 6 | const ( 7 | // TopFree apps 8 | TopFree Collection = "topselling_free" 9 | // TopPaid apps 10 | TopPaid Collection = "topselling_paid" 11 | // TopNewFree apps 12 | TopNewFree Collection = "topselling_new_free" 13 | // TopNewPaid apps 14 | TopNewPaid Collection = "topselling_new_paid" 15 | // TopGrossing apps 16 | TopGrossing Collection = "topgrossing" 17 | // TopTrending apps 18 | TopTrending Collection = "movers_shakers" 19 | ) 20 | -------------------------------------------------------------------------------- /pkg/store/sort.go: -------------------------------------------------------------------------------- 1 | package store 2 | 3 | // Sort of apps 4 | type Sort int 5 | 6 | const ( 7 | // SortHelpfulness method 8 | SortHelpfulness Sort = iota + 1 9 | // SortNewest method 10 | SortNewest 11 | // SortRating method 12 | SortRating 13 | ) 14 | -------------------------------------------------------------------------------- /pkg/suggest/suggest.go: -------------------------------------------------------------------------------- 1 | package suggest 2 | 3 | import ( 4 | "github.com/n0madic/google-play-scraper/internal/util" 5 | "github.com/n0madic/google-play-scraper/pkg/app" 6 | ) 7 | 8 | // Options type alias 9 | type Options = app.Options 10 | 11 | // Get returns up to five suggestion to complete a search query term 12 | func Get(term string, options Options) (list []string, err error) { 13 | payload := "f.req=%5B%5B%5B%22IJ4APc%22%2C%22%5B%5Bnull%2C%5B%5C%22" + term + "%20e%5C%22%5D%2C%5B10%5D%2C%5B2%5D%2C4%5D%5D%22%2Cnull%2C%22generic%22%5D%5D%5D" 14 | 15 | js, err := util.BatchExecute(options.Country, options.Language, payload) 16 | if err != nil { 17 | return nil, err 18 | } 19 | 20 | for _, sugg := range util.GetJSONArray(js, "0.0.#.0") { 21 | list = append(list, sugg.String()) 22 | } 23 | 24 | return list, nil 25 | } 26 | -------------------------------------------------------------------------------- /pkg/suggest/suggest_test.go: -------------------------------------------------------------------------------- 1 | package suggest 2 | 3 | import ( 4 | "testing" 5 | ) 6 | 7 | var resultsCount = 5 8 | 9 | func TestSuggest(t *testing.T) { 10 | list, err := Get("test", Options{}) 11 | if err != nil { 12 | t.Error(err) 13 | } 14 | 15 | if len(list) != resultsCount { 16 | t.Errorf("Expected suggest list length is %d, got %d", resultsCount, len(list)) 17 | } 18 | } 19 | --------------------------------------------------------------------------------