-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[scrape] added more coin games from milan
- Loading branch information
1 parent
398a6e7
commit 9e7e6df
Showing
3 changed files
with
74 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package scrape | ||
|
||
import ( | ||
"log" | ||
|
||
"github.com/gocolly/colly/v2" | ||
) | ||
|
||
func ScrapeCOINMilan() (map[string]any, []map[string]any, error) { | ||
store_id := int64(47) | ||
rs := []map[string]any{} | ||
|
||
collector := colly.NewCollector( | ||
colly.AllowedDomains("www.milan-spiele.de"), | ||
user_agent, | ||
colly.CacheDir(CacheDir), | ||
) | ||
|
||
collector.OnHTML(".master", func(e *colly.HTMLElement) { | ||
raw_price := e.ChildText(".priceRow span.price") | ||
|
||
var stock int | ||
if childHasClass(e, ".delivery", "yellow") { | ||
stock = 1 | ||
} else if childHasClass(e, ".delivery", "green") { | ||
stock = 2 | ||
} else { | ||
stock = 0 | ||
} | ||
|
||
name := e.ChildText(".detail h1") | ||
|
||
item := map[string]any{ | ||
"name": name, | ||
"store_id": store_id, | ||
"store_thumb": "https://www.milan-spiele.de/images/gmt-games-logo.jpg", | ||
"stock": stock, | ||
"price": getPrice(raw_price), | ||
"url": e.Request.URL.String(), | ||
"tag": "COIN", | ||
} | ||
|
||
log.Println(item) | ||
|
||
rs = append(rs, item) | ||
}) | ||
|
||
URLs := []string{ | ||
"https://www.milan-spiele.de/-p-28604.html", | ||
"https://www.milan-spiele.de/fire-lake-second-edition-engl-p-17569.html", | ||
"https://www.milan-spiele.de/-p-34822.html", | ||
"https://www.milan-spiele.de/-p-34842.html", | ||
"https://www.milan-spiele.de/-p-33628.html", | ||
"https://www.milan-spiele.de/-p-27345.html", | ||
"https://www.milan-spiele.de/-p-27751.html", | ||
"https://www.milan-spiele.de/-p-32602.html", | ||
} | ||
|
||
for _, item := range URLs { | ||
collector.Visit(item) | ||
} | ||
|
||
collector.Wait() | ||
|
||
return map[string]interface{}{ | ||
"name": "Milan", | ||
"id": store_id, | ||
"scraped": len(rs), | ||
}, rs, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters