Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 77 additions & 0 deletions -json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions api/search.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
kaldi social house silver spring
29 changes: 29 additions & 0 deletions gmaps/emailjob.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"net/url"
"strings"
"time"

"github.com/PuerkitoBio/goquery"
"github.com/google/uuid"
Expand All @@ -13,6 +14,8 @@ import (
"github.com/gosom/google-maps-scraper/exiter"
)

const emailJobNavigationTimeout = 10 * time.Second

type EmailExtractJobOptions func(*EmailExtractJob)

type EmailExtractJob struct {
Expand Down Expand Up @@ -101,6 +104,32 @@ func (j *EmailExtractJob) ProcessOnFetchError() bool {
return true
}

func (j *EmailExtractJob) BrowserActions(_ context.Context, page scrapemate.BrowserPage) scrapemate.Response {
var resp scrapemate.Response

if setter, ok := page.Unwrap().(interface {
SetDefaultNavigationTimeout(timeout float64)
SetDefaultTimeout(timeout float64)
}); ok {
timeoutMs := float64(emailJobNavigationTimeout.Milliseconds())
setter.SetDefaultNavigationTimeout(timeoutMs)
setter.SetDefaultTimeout(timeoutMs)
}

pageResponse, err := page.Goto(j.GetFullURL(), scrapemate.WaitUntilDOMContentLoaded)
if err != nil {
resp.Error = err
return resp
}

resp.URL = pageResponse.URL
resp.StatusCode = pageResponse.StatusCode
resp.Headers = pageResponse.Headers
resp.Body = pageResponse.Body

return resp
}

func docEmailExtractor(doc *goquery.Document) []string {
seen := map[string]bool{}

Expand Down
26 changes: 12 additions & 14 deletions gmaps/entry.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,10 @@ type Entry struct {
Owner Owner `json:"owner"`
CompleteAddress Address `json:"complete_address"`
About []About `json:"about"`
UserReviews []Review `json:"user_reviews"`
UserReviews []Review `json:"user_reviews,omitempty"`
UserReviewsExtended []Review `json:"user_reviews_extended"`
Emails []string `json:"emails"`
Albums []PhotoAlbum `json:"albums,omitempty"`
}

// entryAlias is used inside Marshal/UnmarshalJSON to avoid infinite recursion
Expand Down Expand Up @@ -316,8 +317,17 @@ func (e *Entry) AddExtraReviews(pages [][]byte) {
}

for _, page := range pages {
remaining := maxExtendedReviews - len(e.UserReviewsExtended)
if remaining <= 0 {
return
}

reviews := extractReviews(page)
if len(reviews) > 0 {
if len(reviews) > remaining {
reviews = reviews[:remaining]
}

e.UserReviewsExtended = append(e.UserReviewsExtended, reviews...)
}
}
Expand Down Expand Up @@ -515,19 +525,7 @@ func EntryFromJSON(raw []byte, reviewCountOnly ...bool) (entry Entry, err error)
5: int(getNthElementAndCast[float64](darray, 175, 3, 4)),
}

// Parse inline reviews from the page data
reviewsI := getNthElementAndCast[[]any](darray, 175, 9, 0, 0)
if len(reviewsI) > 0 {
entry.UserReviews = parseReviews(reviewsI)
} else {
// Try alternative location for reviews
reviewsI = getNthElementAndCast[[]any](darray, 175, 9, 0)
if len(reviewsI) > 0 {
entry.UserReviews = parseReviews(reviewsI)
} else {
entry.UserReviews = make([]Review, 0)
}
}
entry.UserReviews = nil

return entry, nil
}
Expand Down
15 changes: 15 additions & 0 deletions gmaps/job.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ type GmapJob struct {
Deduper deduper.Deduper
ExitMonitor exiter.Exiter
ExtractExtraReviews bool
ExtractExtraPhotos bool
WriterManagedCompletion bool
}

Expand Down Expand Up @@ -101,6 +102,12 @@ func WithExtraReviews() GmapJobOptions {
}
}

func WithExtraPhotos() GmapJobOptions {
return func(j *GmapJob) {
j.ExtractExtraPhotos = true
}
}

func WithWriterManagedCompletion() GmapJobOptions {
return func(j *GmapJob) {
j.WriterManagedCompletion = true
Expand Down Expand Up @@ -152,6 +159,10 @@ func (j *GmapJob) Process(ctx context.Context, resp *scrapemate.Response) (any,
jopts = append(jopts, WithPlaceJobWriterManagedCompletion())
}

if j.ExtractExtraPhotos {
jopts = append(jopts, WithPlaceJobExtraPhotos())
}

placeJob := NewPlaceJob(j.ID, j.LangCode, resp.URL, j.ExtractEmail, j.ExtractExtraReviews, jopts...)

next = append(next, placeJob)
Expand All @@ -167,6 +178,10 @@ func (j *GmapJob) Process(ctx context.Context, resp *scrapemate.Response) (any,
jopts = append(jopts, WithPlaceJobWriterManagedCompletion())
}

if j.ExtractExtraPhotos {
jopts = append(jopts, WithPlaceJobExtraPhotos())
}

nextJob := NewPlaceJob(j.ID, j.LangCode, href, j.ExtractEmail, j.ExtractExtraReviews, jopts...)

if j.Deduper == nil || j.Deduper.AddIfNotExists(ctx, href) {
Expand Down
Loading