diff --git a/README.md b/README.md index 22ad5ae..facd609 100644 --- a/README.md +++ b/README.md @@ -204,6 +204,11 @@ try `./google-maps-scraper -h` to see the command line options available: The plugin must be a shared library (a file with .so or .dll extension). The plugin must be compiled with the following build tags: go build -buildmode=plugin plugins/example.go. Example: If you have your shared library in a folder /home/user/myplugins and it exposesa DummyPrinter symbol the -writer /home/user/myplugins:DummyPrinter + -zoom int + Use this to set the zoom level(0-21) for the search and MUST be use with geo parameter + -geo string + Use this to set the geo coordinates for the search and MUST be use with zoom parameter(example value '37.7749,-122.4194') + ``` ## Using a custom writer @@ -359,4 +364,3 @@ banner is generated using OpenAI's DALE searchapi.com sponsors this project via Github sponsors. If you register via the links on my page I get a commission. This is another way to support my work - diff --git a/gmaps/job.go b/gmaps/job.go index 19f12fd..344261e 100644 --- a/gmaps/job.go +++ b/gmaps/job.go @@ -21,7 +21,7 @@ type GmapJob struct { ExtractEmail bool } -func NewGmapJob(id, langCode, query string, maxDepth int, extractEmail bool) *GmapJob { +func NewGmapJob(id, langCode, query string, maxDepth int, extractEmail bool, geoCoordinates string, zoom int) *GmapJob { query = url.QueryEscape(query) const ( @@ -33,11 +33,19 @@ func NewGmapJob(id, langCode, query string, maxDepth int, extractEmail bool) *Gm id = uuid.New().String() } + mapURL := "" + if geoCoordinates != "" && zoom > 0 { + mapURL = fmt.Sprintf("https://www.google.com/maps/search/%s/@%s,%dz", query, strings.ReplaceAll(geoCoordinates, " ", ""), zoom) + } else { + //Warning: geo and zoom MUST be both set or not + mapURL = fmt.Sprintf("https://www.google.com/maps/search/%s", query) + } + job := GmapJob{ Job: scrapemate.Job{ ID: id, Method: http.MethodGet, - URL: "https://www.google.com/maps/search/" + query, + URL: mapURL, URLParams: map[string]string{"hl": langCode}, MaxRetries: maxRetries, Priority: prio, diff --git a/main.go b/main.go index b87e507..f2c5953 100644 --- a/main.go +++ b/main.go @@ -148,7 +148,7 @@ func runFromLocalFile(ctx context.Context, args *arguments) error { return err } - seedJobs, err := createSeedJobs(args.langCode, input, args.maxDepth, args.email) + seedJobs, err := createSeedJobs(args.langCode, input, args.maxDepth, args.email, args.geoCoordinates, args.zoom) if err != nil { return err } @@ -220,7 +220,7 @@ func produceSeedJobs(ctx context.Context, args *arguments, provider scrapemate.J input = f } - jobs, err := createSeedJobs(args.langCode, input, args.maxDepth, args.email) + jobs, err := createSeedJobs(args.langCode, input, args.maxDepth, args.email, args.geoCoordinates, args.zoom) if err != nil { return err } @@ -234,7 +234,7 @@ func produceSeedJobs(ctx context.Context, args *arguments, provider scrapemate.J return nil } -func createSeedJobs(langCode string, r io.Reader, maxDepth int, email bool) (jobs []scrapemate.IJob, err error) { +func createSeedJobs(langCode string, r io.Reader, maxDepth int, email bool, geoCoordinates string, zoom int) (jobs []scrapemate.IJob, err error) { scanner := bufio.NewScanner(r) for scanner.Scan() { @@ -250,7 +250,7 @@ func createSeedJobs(langCode string, r io.Reader, maxDepth int, email bool) (job id = strings.TrimSpace(after) } - jobs = append(jobs, gmaps.NewGmapJob(id, langCode, query, maxDepth, email)) + jobs = append(jobs, gmaps.NewGmapJob(id, langCode, query, maxDepth, email, geoCoordinates, zoom)) } return jobs, scanner.Err() @@ -274,6 +274,8 @@ type arguments struct { exitOnInactivityDuration time.Duration email bool customWriter string + geoCoordinates string + zoom int } func parseArgs() (args arguments) { @@ -305,6 +307,8 @@ The plugin must implement the scrapemate.ResultWriter interface. The plugin must be a shared library (a file with .so extension). The plugin must be compiled with the following build tags: go build -buildmode=plugin plugins/example.go. The plugins must be placed in the same directory as the binary in a directory called plugins.`) + flag.StringVar(&args.geoCoordinates, "geo", "", "Use this to set the geo coordinates for the search and MUST be use with zoom parameter(example value '37.7749,-122.4194')") + flag.IntVar(&args.zoom, "zoom", 0, "Use this to set the zoom level(0-21) for the search and MUST be use with geo parameter") flag.Parse()